天水齐寿张赵村:c语言初级的小问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/15 05:42:11
要求用指针方式将字符串s的字符进行首尾颠倒。
我编的是:
#include"stdio.h"
#include"string.h"
void main()
{
char s[100];
printf("输入一个字符串:\n");
gets(s);
char *p,c;
p=s;
while(*p!='\0')p++;
c=s[0];s[0]=*p;*p=c;
puts(s);
}
没有error,可是输出时候什么都没有,怎么回事呢?

我也给你发一个吧!~
#include <stdio.h>
#include<string.h>

void main()
{
int i;
char st[100];
gets(st);
puts(st);
for(i=strlen(st)-1;i>=0;i--)
printf("%c",st[i]);

}

#include"stdio.h"
#include"string.h"
void main()
{
char s[100];
printf("输入一个字符串:\n");
gets(s);
char *p,c;
p=s;
while(*p!='\0')
{
c=s[0];s[0]=*p;*p=c;
p++;
}
puts(s);
}
如此修改,加个{},P++地位置改一下

printf("输入一个字符串:\n");
把printf改成scanf最后在句尾加上printf输出你要输出的字母名。

#include"stdio.h"
#include"string.h"
void main()
{
char s[100];
printf("输入一个字符串:\n");
gets(s);
char *p,c;
p=s;
for (p=s;*p!='\0';p++)
p++;
c=s[0];s[0]=*p;*p=c;
puts(s);
}
这样试一下.