I need to rewrite 2-digit input numbers into the output , stopping processing input after reading the number 42.
Input:
1 2 88 42 99
Output:
1 2 88
My code is like this, I can not understand what's wrong:
#include <stdio.h>
#include <stdlib.h>
int main(){
int a=100;
int *n=(int*)malloc(100*sizeof(int));
for(int i=0;i<100;i++){
scanf("%d", &n[i]);
if(n[i]==42){
a=i++;
break;
}
}
for(int i=0;i<a;i++){
printf("%d\n", n[i]);
}
return 0;
}