Simple command text
  #1 (permalink)  
Unread 04-21-2009, 09:50 PM
phewell phewell is offline
Junior Member
 
Join Date: Apr 2009
Posts: 2
Default Simple command text

Hi I am trying to learn programming on my own can anyone tell me why this doesnt work correctly?

#include <stdio.h>


int main()
{
int vName,
vAge,
vHometown;

{
printf( "Please enter your name: " );
scanf( "%s", &vName );
fpurge( stdin );

printf( "Enter your age: " );
scanf( "%d", &vAge );
fpurge(stdin );

printf( "Enter your Hometown: " );
scanf( "%s", &vHometown );
fpurge( stdin );

printf( " Hello %s from %s at the age of %d. ",
vName, vHometown, vAge );
}

return 0;
}
Reply With Quote

  #2 (permalink)  
Unread 04-22-2009, 05:17 PM
~ Identity ~ Identity is offline
Junior Member
 
Join Date: Apr 2009
Location: Costa Mesa, CA
Posts: 9
Send a message via AIM to ~ Identity
Default

It compiled and ran fine for me...
But just to check, since you're making a carbon application, you must also include <Carbon/Carbon.h>

So this:

#include <Carbon/Carbon.h>
#include <stdio.h>


int main()
{
int vName,
vAge,
vHometown;

{
printf( "Please enter your name: " );
scanf( "%s", &vName );
fpurge( stdin );

printf( "Enter your age: " );
scanf( "%d", &vAge );
fpurge(stdin );

printf( "Enter your Hometown: " );
scanf( "%s", &vHometown );
fpurge( stdin );

printf( " Hello %s from %s at the age of %d. ",
vName, vHometown, vAge );
}

return 0;
}


Compiled and ran this:
You just need to include the carbon precompiler directive.

__________________
"Reality continues to ruin my life!" ~ Calvin
Reply With Quote

  #3 (permalink)  
Unread 04-22-2009, 11:02 PM
phewell phewell is offline
Junior Member
 
Join Date: Apr 2009
Posts: 2
Default

Ok i tried that and it does the same thing. it runs and after i input all the info (name, age hometown), it doesnt display the last message ( hello name of hometown at the age of age. Any hints?
Reply With Quote

  #4 (permalink)  
Unread 04-23-2009, 07:42 AM
~ Identity ~ Identity is offline
Junior Member
 
Join Date: Apr 2009
Location: Costa Mesa, CA
Posts: 9
Send a message via AIM to ~ Identity
Default

Found your problem, but I'm not sure how to fix it. (I'm new at this as well, I'm learning C from a Microsoft book, from 1988...)

printf( " Hello %s from %s at the age of %d. ",
vName, vHometown, vAge );

Your problem lies somewhere with the %s specifications, I'm not sure, but I don't think that it is retrieving the previously stored data.

Also, *a guess* don't you have to have data stored before you can clear the buffer with fpurge()? That might be your problem there, that you don't have the scanf() data stored somewhere, so when you go to retrieve it, you get a debugger instead of the print() statement.

Don't rely on my guess though, I just started learning like a week ago, and I don't really understand it yet.
__________________
"Reality continues to ruin my life!" ~ Calvin
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT. The time now is 11:05 PM.


vBulletin skin developed by: eXtremepixels
Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28