I have recently started learning C, and I made this small piece of code, but it's not really working the way I wanted:
#include <stdio.h>
#include <string.h>
int main()
{
int i;
char a[] = "Bill Sarah Alice";
for (i = 0; a[i] != '\0'; i++)
{
if (a[i] != '\t' || a[i] != ' ')
{
printf("%c", a[i]);
}
putchar('\n');
}
return 0;
}
I wanted to print one name per line, but instead its printing one character per line. Can someone tell how should I fix it so it will work?
Every character is not tab or not space. So this
ifwill be passed by every single character. You then output a newline after every single character. So this code is equivalent to this:If you want to print each name on a line, you need to do something more like this: