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

  • #1
WMDhamnekar
MHB
359
28
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.

1653322169276.png


How can I fix this error?
 

Answers and Replies

  • #2
berkeman
Mentor
64,433
15,781
Are you sure you are in the right Documents folder? At the command prompt, what do you get when you type dir *.c ?
 
  • Like
Likes WMDhamnekar
  • #3
WMDhamnekar
MHB
359
28
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.
 
  • #4
pbuk
Science Advisor
Homework Helper
Gold Member
4,084
2,410
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.
 
  • Like
Likes WMDhamnekar, phinds and berkeman
  • #5
WMDhamnekar
MHB
359
28
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:

1653327100570.png

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
 
  • #6
berkeman
Mentor
64,433
15,781
Well, what happens if you put it back?
 
  • #7
WMDhamnekar
MHB
359
28
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.
 
  • #8
berkeman
Mentor
64,433
15,781
Can you post the result of the dir *.c and the compile command using a screenshot of the DOS Box?
 
  • #9
36,854
8,888
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.
 
  • Like
Likes WMDhamnekar and berkeman
  • #10
FactChecker
Science Advisor
Homework Helper
Gold Member
7,720
3,389
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.
 
  • Like
Likes pbuk and berkeman
  • #11
WMDhamnekar
MHB
359
28
Would you tell me which online IDE did you use successfully?
My use of online IDE gave me the following result:
1653375118483.png




1653375194969.png
 
  • #12
pbuk
Science Advisor
Homework Helper
Gold Member
4,084
2,410
See all those characters highlighted in red? Why do you think they are highlighted in red?
 
  • Like
Likes FactChecker
  • #13
WMDhamnekar
MHB
359
28
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? :confused::sorry:
 
  • #14
pbuk
Science Advisor
Homework Helper
Gold Member
4,084
2,410
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.
 
  • Like
Likes FactChecker and WMDhamnekar
  • #15
WMDhamnekar
MHB
359
28
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.


1653395488779.png

This question is solved.:biggrin::smile::oldlaugh:
 
Last edited:
  • Like
Likes berkeman, FactChecker and pbuk

Suggested for: C program could not be compiled and executed at Windows command prompt

Replies
29
Views
1K
Replies
12
Views
256
Replies
1
Views
36
  • Last Post
Replies
12
Views
431
  • Last Post
Replies
14
Views
1K
Replies
11
Views
840
Replies
5
Views
564
  • Last Post
Replies
16
Views
834
Replies
11
Views
657
Top