i have a problem in a program i am making. In my program i need to call a function again and again until the string entered in it is not correct. Initially i was using gets() but it wasn't accepting the string.
i cahnged it to scanf(), so it is accepting first string but not the other strings or integer i am trying to enter after it. My program was correct before i introduced this facility to make it user friendly,its now showing segmentation error:sad:
can you help me please:confused:
rati
0
Junior Poster in Training
Recommended Answers
Jump to Postsorry i am unable to undestand, plz help
Run this code
#include <stdio.h> #include <string.h> int main() { int num, ch; char str[10]; char * ptr = NULL; printf("Input some int: "); scanf("%d", &num); // while ((ch = getchar()) != '\n' && ch != EOF); /* flushing …
Jump to PostRead the rules of the forum Rati.
Jump to Postafter using fgets for inputting the two strings , the code is not even printing the "the string entered is incorrect, reentery/n" it means the problem is somewhere before the printf() statement
It means that ch is NULL. Your code have lot of compile errors. j not defined and tr …
Jump to Post> scanf("%s", &retry);
First buffer overflow - retry is a single char, you can't put a string into a single char.
Second problem, calling a function recursively just to implement a while loop is poor form.
Third, you're mixing scanf() with fgets(), which will surely lead to trouble at some …
Jump to Postit didn't work . i think the segmentation error is because of some logical error not because of scanf(), gets() problem
Thats why we insist to post the code or if you cant, then U need to reconstruct the problem in smaler code. The post I posted don't give seg …
All 34 Replies
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
andor
25
Posting Whiz in Training
Salem
commented:
Salem agrees
+2
rati
0
Junior Poster in Training
Grunt
19
Junior Poster
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
Salem
5,138
Posting Sage
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
rati
0
Junior Poster in Training
andor
25
Posting Whiz in Training
rati
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.