View Full Version : Anyone help me with this simple program?
cornerstone01
04-24-2008, 11:49 AM
Does anyone know why the program is closing before it reads back "Darn glad to meet you x !" ??
#include <stdio.h>
int main()
{
char me[20];
printf("What is your name?:);
scanf("%s", &me);
printf("darn glad to meet you, %s!\n",me);
return(0);
}
The same thing is going on with this other simple program
#include <stdio.h>
int main()
{
printf("Farewell, you damn toad!\n");
return(0);
}
I open it, and it will quickly pop up the CMD window then close quick enough that I can bearly read any of it!!
insain
04-24-2008, 11:53 AM
ROFL
shreal
04-24-2008, 11:55 AM
this serious?
go to start>>run>> type in "cmd" that will start a CMD console....cd into the directory the executable file is located in and execute the program from the cmd console. Your program will run and you will see it working.
Or
You can put a wait(sleep) command into your code so you can see your shit running correctly briefly before the program closes down after executiong completion
try Sleep(5000) before return(0)
5000 = milliseconds. I can't remember ifthe Sleep function is part of an include, but try it out.
villain
04-24-2008, 12:32 PM
if youre using this for a windows machine:
simply
system("pause");
right before your return 0;
why the sleep func?
You forgot to make teh start button dummy
cornerstone01
04-24-2008, 12:34 PM
It is a serious thread, I just bought a book to learn and am going from this point on until my programming class starts.. I will try the pause and sleep cmd
cornerstone01
04-24-2008, 12:36 PM
Ok so opening the CMD line then opening it that way did work correctly, but when I double click on the file it closed quickly without saying glad to meet you (name) .. i will try the pause cmd
cornerstone01
04-24-2008, 12:38 PM
Both sleep and pause worked, thanks guys!
emo porn
04-24-2008, 01:02 PM
the power of dg! we rock we rock
shreal
04-24-2008, 01:08 PM
we rock we rock
LOLLED
if youre using this for a windows machine:
simply
system("pause");
right before your return 0;
why the sleep func?\
system("pause") is bad news
cornerstone01
04-24-2008, 01:23 PM
#include <stdio.h>
#include <stdlib.h>
int main()
{
float height_in_cm;
char height_in_inches[4];
printf ("Enter your height in inches:");
gets (height_in_inches);
height_in_cm= atoi (height_in_inches)*2.54;
printf ("You are %.2f centimeters tall. \n" ,height_in_cm);
sleep(3000);
return (0);
}
Thats not close to a Digital gangster, but well see I am a quick learner
do a gets() command at the end. this way you can just hit enter when youre finished looking over code.
unbounded string copy operation to a fixed length buffer detected
pulaskeet
04-25-2008, 03:14 PM
unbounded string copy operation to a fixed length buffer detected
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.