When I compile this code I get this error:
Q3.c:15: error: incompatible types in assignment
Some knows why?
The purpose of the code is to get 10 names and print them.
#include <stdio.h> #include <string.h> #define NAME 10 #define LONG 50 int main() { int i = 0; char names[NAME][LONG] = {0}; printf("Enter 10 names: "); for(i = 0; i < NAME; i++) { fgets(names[i], LONG, stdin); names[strcspn(names[i], " ")] = 0; } for(i = 0; i < NAME; i++) { printf("%s", names[i]); } }
names[strcspn(names[i], " ")] = 0;
is wrong because names[something] is an array (char[LONG]) and you cannot assign things there.
names[something]
char[LONG]
It seems the line should be
names[i][strcspn(names[i], " ")] = 0;
2.1m questions
2.1m answers
60 comments
57.0k users