我想做一個程序,用戶輸入一個字符串,然後如果他們想輸入他們想要替換的字母和什麼。我想用malloc來設置數組,但我怎麼用scanf來做到這一點?malloc與用戶輸入
請有人幫忙。
謝謝!
這是什麼程序,纔去更換方法如下:
char *s,x,y;
printf("Please enter String \n");
scanf("%s ", malloc(s));
printf("Please enter the character you want to replace\n");
scanf("%c ", &x);
printf("Please enter replacment \n");
scanf("%c ", &y);
prinf("%s",s);
我想你想要POSIX ['getline()'](http://pubs.opengroup.org/onlinepubs/9699919799/functions/getline.html)(不是C99標準的一部分)。 – pmg
您對malloc的使用是非常錯誤的:Malloc獲取字節數並返回一個指針。你傳給它一個指針。 –