K - Troubleshooting C Execution on Windows XP

  • Thread starter Thread starter Dr.Brain
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting the execution of a C program on Windows XP. Participants explore issues related to compiling and running a simple C program, as well as formatting concerns in the code.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant shares a simple C program and asks for feedback on potential flaws in the code and how to execute it properly.
  • Another participant clarifies that simply saving the file as .exe is incorrect; the code must be compiled using the compiler's functionality.
  • There is a question about the necessity of spaces in the printf function, which some participants indicate does not affect the output.
  • A participant mentions using IccWin32 as their C compiler and describes an issue where the MSDOS window closes too quickly to see the output.
  • Suggestions are made to open a command shell to run the program and to navigate to the correct directory before executing the .exe file.
  • Some participants propose adding input prompts to the program to keep the console window open longer, allowing the user to see the output.
  • There is a discussion about the importance of including certain parameters in the main function for better compatibility with APIs, although it is noted that it is not strictly necessary for simple programs.

Areas of Agreement / Disagreement

Participants generally agree on the need to compile the program correctly and the importance of using the command line to execute it. However, there are varying opinions on the necessity of spaces in the printf function and the best practices for writing the main function.

Contextual Notes

Some participants mention the need for specific commands to navigate directories and execute programs in the command shell, indicating potential limitations for users unfamiliar with command line operations.

Who May Find This Useful

New C programmers, individuals troubleshooting similar execution issues on Windows XP, and those interested in learning about command line operations in relation to programming.

Dr.Brain
Messages
539
Reaction score
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
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
 
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
 
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 ?
 
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
 
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();" .
 
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.
 

Similar threads

  • · Replies 19 ·
Replies
19
Views
7K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 29 ·
Replies
29
Views
4K
Replies
14
Views
4K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 40 ·
2
Replies
40
Views
5K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K