C Program where gets(), getchar(), are not working.

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
View Poll Results: Is my query a dumb one?
Yes! 4 50.00%
Ofcourse! 1 12.50%
Not at all! 0 0%
You're a nice guy! 3 37.50%
Voters: 8. You may not vote on this poll

Thread Solved

Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: C Program where gets(), getchar(), are not working.

 
0
  #11
May 5th, 2007
> Gosh! Nope! It still doesnt work.....The interpreter jumps at fgets() I dunno why.
You're mixing a whole bunch of input styles.

In particular, note that scanf() almost always leaves a \n behind, so anything else which uses \n to terminate input (your getline for example, or fgets()) will appear to return immediately.

If you stick to your getline(), then use it for everything, then replace all the scanf calls with calls to getline(), followed by calls to sscanf().


> for(i=0;i<=20;i++)
This runs off the end of the array you're trying to manipulate.

Oh, and main returns int, not void.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,578
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1486
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: C Program where gets(), getchar(), are not working.

 
0
  #12
May 5th, 2007
Originally Posted by brightmohan View Post
I tired the solution posted by ANCIENT DRAGON. It is not working too....:
Post your code. fgets() has been working perfectly on all platforms for over 20 years. Its your code that is wrong, not that function.

Originally Posted by Aia View Post
Take a look at this function:

  1. int *getline( char *string, size_t size )
  2. {
  3. <snip>
  4. return string;
  5. }
Why does that function say its return int * when it is in fact returning char * ?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,042
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: C Program where gets(), getchar(), are not working.

 
0
  #13
May 5th, 2007
Originally Posted by Ancient Dragon View Post
Why does that function say its return int * when it is in fact returning char * ?
The habit of writing int all the time. Yes it should be char *
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,042
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 178
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: C Program where gets(), getchar(), are not working.

 
0
  #14
May 5th, 2007
You have a lot of illegal code in you program. Basically anything where you deal with pointers you use them illegally. We'll call the police.
For example:

  1. title[++i]=*cPtr;
  2. fname[++j]=*cPtr;
  3. lname[++k]=*cPtr;
  4.  
  5. price[++l]=*cPtr;
  6. repcost[++m]=*cPtr;
  7.  
  8. title[p] = tolower(title[p]);
  9. if(title[p]==lookup_field[p])
I am going to guess, here, that the confusion is how you look at pointers.
For example:

  1. char *title[ 20 ];


This is not a pointer to a string. It isn't the same that char *title = string, where string is a char string[20];

char *title[ 20 ] is an array of pointers. Meaning you are declaring 20 char *title, and
each one can point to a different string or a char happy_string[].

Therefore:

  1. title[ ++i ] = *cPtr;
will never work.

Neither
  1. title[p] = tolower( title[ p ] );

The function tolower acepts an integer as a parameter and you are passing to it a char * pointer to a string.
Last edited by Aia; May 5th, 2007 at 7:43 pm.
"If it moves, tax it. If it keeps moving, regulate it, and if it stops moving, subsidize it" - Ronald Reagan
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 12
Reputation: brightmohan is an unknown quantity at this point 
Solved Threads: 0
brightmohan brightmohan is offline Offline
Newbie Poster

Re: C Program where gets(), getchar(), are not working.

 
0
  #15
May 6th, 2007
Dear Geek SALEM,

What you told makes soo much sense. I never knew it before.

Thank you so much for your help.
Mohan Raj!
Last edited by brightmohan; May 6th, 2007 at 1:05 am. Reason: I had to address it to SALEM
You have to let it all go Neo! Fear, Doubt, Disbelief!
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 12
Reputation: brightmohan is an unknown quantity at this point 
Solved Threads: 0
brightmohan brightmohan is offline Offline
Newbie Poster

Re: C Program where gets(), getchar(), are not working.

 
0
  #16
May 6th, 2007
Originally Posted by Aia View Post
You have a lot of illegal code in you program. Basically anything where you deal with pointers you use them illegally. We'll call the police.
For example:
Gosh!!! If I do Illegeal with pointer to the pointer, You might call the MILLITARY....lol

Originally Posted by Aia View Post
I am going to guess, here, that the confusion is how you look at pointers.
For example:

  1. char *title[ 20 ];


This is not a pointer to a string. It isn't the same that char *title = string, where string is a char string[20];

char *title[ 20 ] is an array of pointers. Meaning you are declaring 20 char *title, and
each one can point to a different string or a char happy_string[].

Therefore:

  1. title[ ++i ] = *cPtr;
will never work.

Neither
  1. title[p] = tolower( title[ p ] );

The function tolower acepts an integer as a parameter and you are passing to it a char * pointer to a string.
Thank You! I have cleared all the bugs related to ILLEGAL POINTER CONVERSIONs and ASSIGNMENTS. Now I have 0 Warnings. 0 Errors.

Time is so precious. Thank you so much for your time Dear Geek Aia and to all the geeks who helped me . You're Great!

I registered with this forum just 10 hours ago and I'm amazed at the way you geeks helped me out. Thank you so very much. I'll try my best to contribute.

One again. Thank you.
Mohan Raj B
Last edited by brightmohan; May 6th, 2007 at 1:25 am. Reason: Wanted to thank everyone.
You have to let it all go Neo! Fear, Doubt, Disbelief!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC