| | |
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 |
> 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.
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.
•
•
•
•
I tired the solution posted by ANCIENT DRAGON. It is not working too....:
•
•
•
•
Take a look at this function:
C Syntax (Toggle Plain Text)
int *getline( char *string, size_t size ) { <snip> return string; }
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.
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:
I am going to guess, here, that the confusion is how you look at pointers.
For example:
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:
will never work.
Neither
The function tolower acepts an integer as a parameter and you are passing to it a char * pointer to a string.

For example:
•
•
•
•
C Syntax (Toggle Plain Text)
title[++i]=*cPtr; fname[++j]=*cPtr; lname[++k]=*cPtr; price[++l]=*cPtr; repcost[++m]=*cPtr; title[p] = tolower(title[p]); if(title[p]==lookup_field[p])
For example:
C Syntax (Toggle Plain Text)
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:
C Syntax (Toggle Plain Text)
title[ ++i ] = *cPtr;
Neither
C Syntax (Toggle Plain Text)
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
•
•
Join Date: May 2007
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
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:
•
•
•
•
I am going to guess, here, that the confusion is how you look at pointers.
For example:
C Syntax (Toggle Plain Text)
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:
will never work.C Syntax (Toggle Plain Text)
title[ ++i ] = *cPtr;
NeitherC Syntax (Toggle Plain Text)
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.
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!
![]() |
Similar Threads
- simple c++ program (any help would be greatly appreciated) (C++)
- Assistance with change program (C++)
- I need a program for fixing errors and stuff... (Legacy and Other Languages)
- Running My Program (C++)
- Deitel's "C++ How To Program" exercise 2.18 (C++)
- WinXP installation program (Windows NT / 2000 / XP)
- Need to Log Program Usage (Windows NT / 2000 / XP)
- Default program to open *.pdf (Mac Software)
Other Threads in the C Forum
- Previous Thread: WinApi GUI Menu Problem
- Next Thread: search binary tree
| Thread Tools | Search this Thread |
Tag cloud for C
* adobe api append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createcopyoffile createprocess() csyntax directory dynamic execv feet fgets file floatingpointvalidation fork frequency function getlogicaldrivestrin givemetehcodez global gtkgcurlcompiling gtkwinlinux highest histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list lowest matrix meter microsoft mqqueue multi mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power program programming pyramidusingturboccodes read recursion recv recvblocked repetition reversing scheduling segmentationfault send single socketprogramming spoonfeeding stack standard strchr string suggestions system test testautomation unix urboc user whythiscodecausesegmentationfault win32api windows.h windowsapi






