Your code as shown has at least a couple of syntax errors.
The string in printf(LEV3"Student No. ...
has that stray "LEV3".
Is that supposed to part of the format string or what is it?
In your if
that checks for newline, you left off the string name
when attempting to set a null value in the string. Instead of
[LEN-1] = '\0';
you should have studno[LEN-1] = '\0';
.
This function (number
) calls itself... Eek! Did you mean for this function to be recursive? It's unclear what the purpose is. Your local variable i
is being incremented as if the next call to number
will see it, but it won't since it's a local variable. For something like this, you just want a loop, not recursion.
So using @Gangadhar's suggestion, your code ultimately should look like this for reading the line. I'll leave the rest for you to update since I'm not sure what your intention is with i
etc, and you haven't explained what the format of the input is. I am assuming studno
is an array of char pointers, but you're not showing it.
void number()
{
printf("Student No. (20XXXXXXX):\t");
int x = 0, i = 0;
fgets(studno[i], LEN, stdin);
if ('\n' == studno[i][strlen(studno)-1])
{
studno[i][strlen(studno)-1] = '\0';
}
...
}