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 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 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 …
Jump to PostThe seg fault is becouse if you dont have ';' then pch is NULL. So seg fault will happen only if you dont have ';' in the input string. You need to change the logic
#include<stdio.h> #include <string.h> #include<stdlib.h> void function(char *); int j; struct test { …
Jump to PostRight now i am testing for ch, and before pch tests for ; ch is null
so the program should end there itself when ch is null, why would it continue till pch??The point is that ch is not NULL. Check the debug printf in my post
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,265 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.