利用指针编写一个小程序
题目:given an array such as
char chars[]={'a',' ','b',' ','c',' ','d'};
write a program that replaces all the blank elements in a character array with the underline character‘_’.
use a pointer,rather than a subscript ,to access the elements of the array.
我自己编的程序:
#include"stdio.h"
main()
{
char chars[]={'a',' ','b',' ','c',' ','d'};
char *p;
int i,t;
p=&chars[1];
for(i=1;i<=3;i++)
{*p='_';
p+=2;}
for(t=0;t<7;t++)
printf("%c",chars[t]);
}
无法输出,请问下下哪里又问题。。,