I'm trying to trying to print the output but my code keep getting c compile error: ISO C forbids comparison between pointer and integer, The error is in else if :
#include <stdio.h>
#include <string.h>
int main (){
char BT [5][100];
for (int i = 1; i<=2; i ){
printf("\nInsert book title:");scanf("%[^\n]", &BT[i]); getchar ();
}
printf("\nOur Collections :\n");
for (int i = 1; i<= 2 ; i ){
for (int i = 0; i< strlen(BT[i]); i ){
int k;
if ( i == 0 && BT[i][k] != ' ') {
printf("Shelf code : %c\n", BT[i][k]);
}
else if ( i > 0 && BT[i - 1] == ' ') {
printf("Shelf code : %c\n", BT[i][k]);
}
}
}
return 0;
}
Thanks in advance!
CodePudding user response:
- You compile C program using C compiler which is wrong.
BT[i - 1]
is an char array acting as lvalue (pointer) not character. You compare it to an integer' '
. Even in C it will raise a warning and it is definitely not what you want.
CodePudding user response:
There are many mistakes.
For example indices in C for arrays start from 0
but you are using for loops where indices start from 1
like
for (int i = 1; i<=2; i ){
and below in the code you are trying to access BT[0]
.
Or the function scanf
for reading a string expects an argument of the type char *
but you are passing an argument of the type char ( * )[100]
.
scanf("%[^\n]", &BT[i]);
At least you should write
scanf("