K - Troubleshooting C Execution on Windows XP

  • Thread starter Dr.Brain
  • Start date
In summary, you compiled your .c file into an .exe, but when you tried to run it, it showed a MSDOS window that disappeared after a short time.
  • #1
Dr.Brain
538
2
I am a newbie to C and i am learning it all by myself without any teacher.

Ok i wrote this programme in my notepad and saved it as dd.c on my desktop:


#include <stdio.h>

int main()
{
int a, b, c;
a = 5;
b = 7;
c = a + b;
printf("%d + %d = %d\n", a, b, c);
return 0;
}


Please tell me if there is a flaw in my coding . I downloaded a free C-compiler , and wanted to convert my .c to .exe , executable file .
So what I did was that I opened my .c file with this compiler and then saved it agains as dd.exe on my desktop , but when i opened the .exe by clicking on it , it displays a series of programmes and tells me to choose the most apt programme out of all those.So how do i run my programme. Through my code, I want that the output on my screen displays 5+7=12 . Should I go to DOS for execution or what? and how do I reach DOS from XP? :blushing:


BJ
 
Computer science news on Phys.org
  • #2
and ye sone more thing , is the space necessary between %d and + i, and betweeen a.b and c in the following code:

printf("%d + %d = %d\n", a, b, c);


??

BJ
 
  • #3
I do not see any error in your code.

You should not simply save the file as .exe, but you have to instruct your compiler to compile the file that you wrote in notepad (you can save your file with any extension that you like, but you will have to compile the file so that it will become an executable before you get something that you can execute).

You should do something like: open the file in your "compiler" and choose compile. If you say what compiler you use people can give more appropriate advise.

Dr.Brain said:
and how do I reach DOS from XP?
start menu --> run --> cmd<enter>

______________
printf("%d + %d = %d\n", a, b, c);
would generate the same as
printf("%d + %d = %d\n",a,b,c);
both give:
5 + 7 = 12

printf("%d+%d=%d\n",a,b,c);
would give
5+7=12
 
  • #4
I use IccWin32 freeware C-compiler.

Ok i compiled the .c file using my compiler , AFter the process completed , it created some files in the same folder as that of .c file . I found the .exe file and clicked on it , it shows a MSDOS window which disappears in less than half a second :(

where is 5+7=12 ?
 
  • #5
Ok i just managed to know that the MSDOS windows shows 5 + 7 =12 for a fraction of a second . Is there a command to increase the viewing time of this DOS window.

BJ
 
  • #6
You have to open a command shell: Start->Run->cmd [do not use: the more limited command.com], navigate to that directory: cd "somedirectory" [you may have to use quotes around the directory name], then execute that program by typing in its name.

If you want to avoid the command line interface, you can also add a few lines that ask for input.

For instance, "scanf("%d", &a);", which waits for an integer to be assigned to a. See http://computer.howstuffworks.com/c7.htm .

You could also use the declaration "char reply;" , later followed by what amounts to a HIT A KEY TO CONTINUE: "reply = getch();" .
 
  • #7
spaces don't matter unless its between to variable names
scanf(); kbhit(); getch(); getche(); some time command delay(i think its actually delay())

if your runninga console programm its usually stanard to include

int main(int argc,char**argv)...though you don'treally need it for such simpe programme its a good habit to remember it though because some APIs require you to use it.
 

1. What is "C - execution trouble"?

"C - execution trouble" is a common error that occurs when executing a C program. It usually indicates that there is a problem with the code, such as a syntax error or an undefined variable.

2. How can I fix "C - execution trouble"?

To fix this error, you will need to carefully review your code and look for any mistakes that may be causing the issue. This could include typos, missing semicolons, or incorrect variable declarations. Debugging tools like a debugger or printf statements can also help identify the problem.

3. What are some common causes of "C - execution trouble"?

There are several common causes of this error, including syntax errors, uninitialized variables, incorrect data types, and out-of-bounds array access. It can also be caused by issues with the compiler or operating system.

4. How can I prevent "C - execution trouble" from occurring?

The best way to prevent this error is to write clean and well-structured code. This includes using proper indentation, commenting your code, and declaring variables before using them. Additionally, regularly testing and debugging your code can help catch and fix any potential issues before they cause trouble.

5. Can "C - execution trouble" be caused by hardware issues?

While it is possible for hardware issues to cause problems with C program execution, it is not a common cause of the "C - execution trouble" error. More often, this error is caused by software issues such as coding mistakes or compiler errors.

Similar threads

Replies
19
Views
1K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
14
Views
2K
  • Computing and Technology
Replies
3
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
  • Programming and Computer Science
Replies
9
Views
994
  • Programming and Computer Science
Replies
5
Views
1K
  • Programming and Computer Science
Replies
2
Views
339
  • Engineering and Comp Sci Homework Help
Replies
7
Views
982
Replies
16
Views
2K
Back
Top