This program should replace one space with an x, using only getchar() and putchar(). My approach was to store the space in a buffer and then print it out. But the program replaces every space with an x. Can someone help me out?
#include <stdio.h>
#define MAX 1
char arr[MAX];
int ret = 0;
int main()
{
for(int i=0; ; )
{
if ( (ret = getchar())!= EOF)
{
putchar(ret);
}
if(ret==' ')
{
arr[i]=ret;
arr[i]='x';
putchar(arr[i]);
}
}
return 0;
}
Aucun commentaire:
Enregistrer un commentaire