So i wanna to make a program that if I :
Input : 1 & 2 & 3
Output : & 1
#include <stdio.h>
int main()
{
char array[5];
int arr[5];
for (int i = 0; i < 5; i ){
if (i%2 == 0){
scanf("%d",arr[i]);
} else {
scanf(" %s ",array[i]);
}
}
printf("%s",array[1]);
printf(" %d",arr[0]);
}
CodePudding user response:
You are using scanf incorrectly.
Write
if (i%2 == 0){
scanf( "%d", &arr[i]);
} else {
scanf( " %c", &array[i]);
}
or
if (i%2 == 0){
scanf( "%d", arr i );
} else {
scanf( " %c", array i );
}
Also in the call of printf write
printf("%c",array[1]);
CodePudding user response:
You need to take input of a character but you are using wrong identifier. Instead of this:
scanf( " %s", &array[I]);
Use this:
scanf( " %c", &array[I]);