R
Robert Smith
I've written this small program to extract names from a list. It does what
it it supposed to do, but then crashes (segmentation fault) at the very end.
Can anyone tell me why?
#include <stdio.h>
#include <stdlib.h>
int main() {
char *test = "file1.jpg\nfile2.jpg\nfile3.jpg\nfilex.tga\n";
char *p = test;
char temp[13];
int i = 0; // index
memset(temp,0,13);
while (p) {
while (*p != '\n') {
temp = *p++;
i++;
}
puts(temp);
i=0;
p++; // bump over newline
}
}
it it supposed to do, but then crashes (segmentation fault) at the very end.
Can anyone tell me why?
#include <stdio.h>
#include <stdlib.h>
int main() {
char *test = "file1.jpg\nfile2.jpg\nfile3.jpg\nfilex.tga\n";
char *p = test;
char temp[13];
int i = 0; // index
memset(temp,0,13);
while (p) {
while (*p != '\n') {
temp = *p++;
i++;
}
puts(temp);
i=0;
p++; // bump over newline
}
}