# C program could not be compiled and executed at Windows command prompt

WMDhamnekar
MHB
TL;DR Summary
I have downloaded and installed ' C c-programs application from Microsoft Windows store. I copied one program named 'Days Convertion' from it to my Notepad++ and saved it as c source file in the Documents folder. When I tried to compile it using gcc, gcc said No such file or directory. How can I fix this error?

When I tried to run this c program in online IDE, it showed several compiling errors. https://ide.geeksforgeeks.org/?ref=ndm
C:
/*    Write a c program to convert given number of days to a measure of time

*    given in years, weeks and days. For example 375 days is equal to 1 year

*    1 week and 3 days (ignore leap year)

*/

#include stdio.h

#define DAYSINWEEK 7

void main()

{

int ndays, year, week, days;

printf("Enter the number of days\n");

scanf("%d",&ndays);

year = ndays/365;

week = (ndays % 365)/DAYSINWEEK;

days = (ndays%365) % DAYSINWEEK;

printf ("%d is equivalent to %d years, %d weeks and %d days\n",

ndays, year, week, days);

}

/*-----------------------------------------------

When I tried to compile it using gcc at windows command prompt, I got the following error several times. After giving this command at command prompt, 'DaysConvertion.c' file disappeared from the Documents folder.

How can I fix this error?

Mentor
Are you sure you are in the right Documents folder? At the command prompt, what do you get when you type dir *.c ?

WMDhamnekar
WMDhamnekar
MHB
Are you sure you are in the right Documents folder? At the command prompt, what do you get when you type dir *.c ?
Yes. I am in appropriate documents folder. In user variables, I set the PATH for gcc downloaded from https://winlibs.com/#usage-commandprompt. C: \mingw W64\bin.

Homework Helper
Gold Member
The file names are the wrong way round in the command: you are telling gcc to compile the source file DaysConvertion (which doesn't exist) to produce the object file DaysConvertion.c.

Just type gcc DaysConvertion.c and see what happens.

By the way "convertion" is spelled "conversion" in English.

WMDhamnekar, phinds and berkeman
WMDhamnekar
MHB
The file names are the wrong way round in the command: you are telling gcc to compile the source file DaysConvertion (which doesn't exist) to produce the object file DaysConvertion.c.

Just type gcc DaysConvertion.c and see what happens.

By the way "convertion" is spelled "conversion" in English.
Thanks for finding out my and author's spelling mistake (author means author of 'C c-programs ' application from Microsoft windows store).
After gcc compiling command at command prompt, the file was no more in the documents folder.
The result of your suggestion is as follows:

My advise to you is Just run this program in the online IDE given by me , you will see plenty of errors in the program

Mentor
Well, what happens if you put it back?

WMDhamnekar
MHB
Well, what happens if you put it back?
When I do these steps several times using Notepad++, I repeatedly get the same error at the command prompt.

Mentor
Can you post the result of the dir *.c and the compile command using a screenshot of the DOS Box?

Mentor
WMDhamnekar said:
When I tried to run this c program in online IDE, it showed several compiling errors. https://ide.geeksforgeeks.org/?ref=ndm

After I fixed one syntax error, I was able to get the program to run in the online IDE.
This line - #include stdio.h
should be written as #include <stdio.h>

When I ran that code, I entered 300, and the program reported "300 is equivalent to 0 years, 42 weeks and 6 days".

I don't use gcc, so can't give you any help on that compiler, other than to suggest that you don't have things set up correctly.

WMDhamnekar and berkeman
Homework Helper
Gold Member
Your earlier command in post #1 told gcc to overwrite your .c file with the compiler output. That might have wiped out your code .c file. The dir command in your post #5 says that the file doesn't exist, so what did you expect gcc to do?
I suggest that you start over and put your code in the DaysConvertion.c file. This time use the simple command "gcc DaysConvertion.c" and see what happens.

pbuk and berkeman
WMDhamnekar
MHB
Would you tell me which online IDE did you use successfully?
My use of online IDE gave me the following result:

Homework Helper
Gold Member
See all those characters highlighted in red? Why do you think they are highlighted in red?

FactChecker
WMDhamnekar
MHB
See all those characters highlighted in red? Why do you think they are highlighted in red?
I don't know the meaning of …, .., . in red colour in the program I put in the online IDE. In my opinion, these red dots represents errors. But how to debug this program is my problem. Do you know it's solution?

Homework Helper
Gold Member
In my opinion, these red dots represents errors. But how to debug this program is my problem. Do you know it's solution?
You could try deleting the errors (were they there in the code you copied or do you think they have appeared as part of the copying and pasting process?)

Also note that the Notepad doesn't work well with text copied from a web page, use a proper text editor designed for code like Visual Studio Code.

FactChecker and WMDhamnekar
WMDhamnekar
MHB
You could try deleting the errors (were they there in the code you copied or do you think they have appeared as part of the copying and pasting process?)

Also note that the Notepad doesn't work well with text copied from a web page, use a proper text editor designed for code like Visual Studio Code.
These errors were appeared as a part of copying and pasting process.

This question is solved.

Last edited:
berkeman, FactChecker and pbuk