I give the input and when i press enter i get a segfault! can you help me?
thanks
Code:
#include <stdio.h>
#include <ctype.h>
#define N 100
#define M 37
#define AEM_MAX 4
int main (int argc, char *argv[]) {
char studentdata[N][M], c;
int i, pos;
for (i=0;i<N;i++) {
fgets(studentdata[i],M,stdin);
if (studentdata[i][0]=='-') {
break;
}
else {
do {
c=getchar(); /*Aporofhsh tou kenou*/
} while (c!='\n');
}
}
for (i=0;i<N;i++) {
studentdata[i][31]='\0'; /*antikatastash tou ' ' me to \0 */
}
for (i=0;i<N-5;i++) { /*Bazw -5 giati den thelw na exw thn telia ston elegxo*/
if (ispunct(studentdata[i])) {
pos=i;
}
}
printf("%s. ",studentdata[pos+1]); /*Ektypwsh tou prwtou grammatos tou onomatos*/
for (i=0;i<pos;i++) {
if (isalpha(studentdata[i])) {
printf("%s",studentdata[i]);
}
}
printf(" ");
for (i=0;i<AEM_MAX;i++) { /*Dhlwsa to AEM_MAX ws 4 dioti to AEM einai to polu 5 arithmoi*/
if (isdigit(studentdata)) { /*opote mou arkei o elegxos apo to stoixeio 0 ews to stoixeio 4*/
printf("%s",studentdata[i]);
}
}
printf(" ");
return(0);
}