Click here to Skip to main content
15,911,531 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: To write a c program to maintain a log of football match b/w 2 teams and then compare the results of the log entered by user and announce the winner. Pin
Vaclav_28-Dec-17 13:24
Vaclav_28-Dec-17 13:24 
GeneralRe: To write a c program to maintain a log of football match b/w 2 teams and then compare the results of the log entered by user and announce the winner. Pin
Victor Nijegorodov28-Dec-17 21:17
Victor Nijegorodov28-Dec-17 21:17 
GeneralRe: To write a c program to maintain a log of football match b/w 2 teams and then compare the results of the log entered by user and announce the winner. Pin
Tarun Jha31-Dec-17 12:30
Tarun Jha31-Dec-17 12:30 
QuestionClasses hierarchy? Pin
Vaclav_24-Dec-17 7:53
Vaclav_24-Dec-17 7:53 
AnswerRe: Classes hierarchy? Pin
Rick York24-Dec-17 10:36
mveRick York24-Dec-17 10:36 
QuestionCode consuming lot of RAM (Memory) Pin
User 1350945018-Dec-17 23:21
professionalUser 1350945018-Dec-17 23:21 
AnswerRe: Code consuming lot of RAM (Memory) Pin
Manish K. Agarwal19-Dec-17 0:24
Manish K. Agarwal19-Dec-17 0:24 
GeneralRe: Code consuming lot of RAM (Memory) Pin
User 1350945019-Dec-17 0:30
professionalUser 1350945019-Dec-17 0:30 
GeneralRe: Code consuming lot of RAM (Memory) Pin
Manish K. Agarwal19-Dec-17 0:48
Manish K. Agarwal19-Dec-17 0:48 
GeneralRe: Code consuming lot of RAM (Memory) Pin
User 1350945019-Dec-17 2:02
professionalUser 1350945019-Dec-17 2:02 
QuestionRe: Code consuming lot of RAM (Memory) Pin
Jochen Arndt19-Dec-17 0:57
professionalJochen Arndt19-Dec-17 0:57 
AnswerRe: Code consuming lot of RAM (Memory) Pin
User 1350945019-Dec-17 2:01
professionalUser 1350945019-Dec-17 2:01 
GeneralRe: Code consuming lot of RAM (Memory) Pin
Jochen Arndt19-Dec-17 2:35
professionalJochen Arndt19-Dec-17 2:35 
AnswerRe: Code consuming lot of RAM (Memory) Pin
Jochen Arndt19-Dec-17 2:59
professionalJochen Arndt19-Dec-17 2:59 
QuestionRe: Code consuming lot of RAM (Memory) Pin
David Crow19-Dec-17 4:12
David Crow19-Dec-17 4:12 
AnswerRe: Code consuming lot of RAM (Memory) Pin
User 1350945019-Dec-17 5:14
professionalUser 1350945019-Dec-17 5:14 
AnswerRe: Code consuming lot of RAM (Memory) Pin
David Crow19-Dec-17 5:28
David Crow19-Dec-17 5:28 
AnswerRe: Code consuming lot of RAM (Memory) Pin
User 1350945019-Dec-17 10:03
professionalUser 1350945019-Dec-17 10:03 
AnswerRe: Code consuming lot of RAM (Memory) Pin
KarstenK20-Dec-17 6:47
mveKarstenK20-Dec-17 6:47 
QuestionGet Supported File System Pin
john563218-Dec-17 22:48
john563218-Dec-17 22:48 
AnswerRe: Get Supported File System Pin
Jochen Arndt18-Dec-17 23:03
professionalJochen Arndt18-Dec-17 23:03 
GeneralRe: Get Supported File System Pin
john563218-Dec-17 23:14
john563218-Dec-17 23:14 
GeneralRe: Get Supported File System Pin
Jochen Arndt18-Dec-17 23:53
professionalJochen Arndt18-Dec-17 23:53 
QuestionSearching string not working Pin
Anonygeeker18-Dec-17 22:10
Anonygeeker18-Dec-17 22:10 
AnswerRe: Searching string not working Pin
Richard MacCutchan18-Dec-17 22:40
mveRichard MacCutchan18-Dec-17 22:40 
Anonygeeker wrote:
But I am getting segmentation fault. Why?
Because your original array does not contain a null terminator. You have:
C++
char *a[]={"abc","xyz","lmn","NULL"};

but "NULL" is a quoted string, not a NULL value, so your loop will continue until it causes the fault.

You also have:
C++
printf("%c\n",a[i]);

but the array is an array of pointers, not characters. You need to use the string identifier in your format string like:
C++
printf("%s\n",a[i]); // use s to print a character aray

And finally (although I may have missed other mistakes) you have:
C++
char *b; // what does this point to?
int l;
printf("\nenter string to find\n");
fgets(b,MAX,stdin); // but b does not point to anything
printf("%c",*b); // again %c means a single character

It should be:
C++
char b[MAX];
int l;
printf("\nenter string to find\n");
fgets(b,MAX,stdin);
printf("%s",b);


I strongly suggest you get a good book on C and learn the basics of single elements, arrays, pointers, printf format strings etc.

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.