C语言题目
将一个字符串str的内容颠倒过来,并输出。str的长度不超过100个字符。输入
输入包括一行。第一行输入的字符串。
输出
输出转换好的逆序字符串。
样例输入
I am a student
样例输出
tneduts a ma I
用C语言怎么做 --------------------编程问答-------------------- #include <string.h>
#include <stdio.h>
#define TOTAL_NUM 10
#define TOTAL_CHAR 30
#define TOTAL_BUF 256
int main(void)
{
char allname[TOTAL_BUF] = "I am a student";
char name[TOTAL_NUM][TOTAL_CHAR] = {0};
char *pStr = NULL;
char *pStep = " ";
int nIdx = 0;
printf("the string is: %s\n", allname);
pStr = strtok(allname, pStep);
if (NULL == pStr)
{
printf("no any string !\n");
return -1;
}
strcpy(name[nIdx++], pStr);
while (pStr = strtok(NULL, pStep))
{
if (nIdx < TOTAL_CHAR)
{
strcpy(name[nIdx++], pStr);
}
}
printf("change postion string is: ");
for (; nIdx-- > 0; )
{
printf("%s ", name[nIdx]);
}
printf("\n");
return 0;
}
//代码已测试,楼主试试看 --------------------编程问答--------------------
--------------------编程问答--------------------
#include <string.h>
#include <stdio.h>
#define TOTAL_NUM 10
#define TOTAL_CHAR 30
#define TOTAL_BUF 256
int main(void)
{
char allname[TOTAL_BUF] = "I am a student";
char name[TOTAL_NUM][TOTAL_CHAR] = {0};
char *pStr = NULL;
char *pStep = " ";
int nIdx = 0;
printf("the string is: %s\n", allname);
pStr = strtok(allname, pStep);
if (NULL == pStr)
{
printf("no any string !\n");
return -1;
}
strcpy(name[nIdx++], pStr);
while (pStr = strtok(NULL, pStep))
{
if (nIdx < TOTAL_CHAR)
{
strcpy(name[nIdx++], pStr);
}
}
printf("change postion string is: ");
for (; nIdx-- > 0; )
{
printf("%s ", name[nIdx]);
}
printf("\n");
return 0;
}
//代码已测试,楼主试试看
--------------------编程问答--------------------
#include<stdio.h>
void main()
{
char s[80]="I am a student";
int i,L;
L = strlen(s); // 测字符串长度
for (i=0;i<L;i++){
printf("%c",s[L-i-1]); //倒着次序输出
}
}
//对不起看错题了,试试这个 有问题回我
这个应该可以
补充:.NET技术 , C#