有大神可以帮我写一个简单的C语言程序吗T.T 跪求各位大神

要求都再图片上,先输入句子然后 一个个选择就好。真的很需要各位帮助。我也没有什么财富值,全都放进去了。大神们帮帮忙,小弟跪谢。我visual studio 2013版本的

第1个回答  推荐于2016-05-22
#include <iostream>

#define MaxWords 20

int _tmain(int argc, _TCHAR* argv[])
{
char Sentence[MaxWords+1];
const char * pHint ="Word Processor\n"
"(1) Enter the sentence (Max. 20 words)\n"
"(2) How many words in the sentence?\n"
"(3) Reverse the whole sentence from last character to the first.\n"
"(4) Find the number of instances of character.\n"
"(5) Find the position of a specified character at the first occurrence.\n"
"(6) Find the position of a specified character at the last occurrence.\n"
"(7) Reverse all the words in the sentence.\n"
"(0) Quit\n"
"Enter Choice:\n";
printf(pHint);
char Choice;
Choice =getchar();
//std::cin>>Choice;
while(Choice != '0')
{

if(Choice == '1')
{
//提示输入
printf("Please input your sentence(Max. 20 words):\n");
//清空句子
memset(Sentence,0,sizeof(Sentence));
//键盘输入句子保存到Sentence
gets_s(Sentence,MaxWords);
std::cin.get(Sentence,MaxWords+1);//使用cin.get来接收空格,并且长度限制MaxWords+1
//显示输入结果 ;
printf("Your sentence of input is :%s\n",Sentence);
}
else if(Choice == '2')
{
//是否统计空格
int nSentenceLen=0,nNoSpaceLen=0;
char * p =Sentence;
while( *p !='\0')
{
if(*p !=' ')
nNoSpaceLen++;
nSentenceLen++;
p++;
}
printf("The sentence has %d words contain space.\n",nSentenceLen);
printf("The sentence has %d words excluding space.\n",nNoSpaceLen);
}
else if(Choice == '3')//翻转所有字母
{
char * p1,*p2,c;
p1 =Sentence;
p2 =Sentence+strlen(Sentence)-1;
while(p2>p1)
{
bool bP1Character=false,bP2Character=false;
if((*p1 >='a' && *p1<='z') ||(*p1>='A' && *p1<='Z'))//p1是母
{
bP1Character=true;
}
else
p1++;

if((*p2 >='a' && *p2<='z') ||(*p2>='A' && *p2<='Z'))//p2是母
{
bP2Character=true;
}
else
p2--;
if(bP1Character && bP2Character)
{
c=*p1;
*p1=*p2;
*p2=c;
p1++;
p2--;
}
}
printf("The sentence after reverse is:%s\n",Sentence);
}
else if(Choice == '4')//统计字母个数
{

int nCharacterCount=0;
char * p =Sentence;
while( *p !='\0')
{
if((*p >='a' && *p<='z') ||(*p>='A' && *p<='Z'))
nCharacterCount++;
p++;
}
printf("The number of instances of character is %d.\n",nCharacterCount);
}
else if(Choice == '5')//查找制定字符出现的第一个位置(从前至后)
{
printf("Please input the character to find(form first to last).\n");
char c,*p=Sentence;
getchar();
std::cin>>c;
int pos=0;
while( *p !='\0')
{
if(*p == c)
{
pos = p-Sentence+1;
break;
}
p++;
}
if(pos!=0)
printf("The character of %c in the sentence position is %d.\n",c,pos);
else
printf("Can not find the character %c in the sentence your input.",c);
}
else if(Choice == '6')//查找制定字符出现的第一个位置(从后至前)
{
printf("Please input the character to find(form last to first).\n");
char c,*p=Sentence+strlen(Sentence)-1;
getchar();
std::cin>>c;
int pos=0;
while (p >= Sentence)
{
if(*p == c)
{
pos = p-Sentence+1;
break;
}
p--;
} ;
if(pos!=0)
printf("The character of %c in the sentence position is %d.\n",c,pos);
else
printf("Can not find the character %c in the sentence your input.",c);
}
else if(Choice == '7')//翻转所有字符
{
char * p1,*p2,c;
p1 =Sentence;
p2 =Sentence+strlen(Sentence)-1;
while(p2>p1)
{
c=*p1;
*p1=*p2;
*p2=c;
p1++;
p2--;
}
printf("The sentence after reverse is:%s\n",Sentence);
}
else
{
printf("Invalid choice,please enter right choice:\n");
}

getchar();
std::cin>>Choice;
}
return 0;
}
/*
iosteam应该是c++的,stdio.h是c的,自己试着改一下,应该就是cin的使用
*/追问

运行,提示_TCHAR indentifer

追答

这个不是unicode的,如果要使用中文你就把char改成TCHAR,stren改成wcslen等,注意项目的字符集

本回答被提问者采纳

有大神可以帮我写一个简单的C语言程序吗T.T 跪求各位大神
define MaxWords 20 int _tmain(int argc, _TCHAR* argv[]){ char Sentence[MaxWords+1];const char * pHint ="Word Processor\\n""(1) Enter the sentence (Max. 20 words)\\n""(2) How many words in the sentence?\\n""(3) Reverse the whole sentence from last character to the ...

c语言,求大神T^T
帮你写了一个,可以直接运行的程序:include<stdio.h> int main(){ int a, b, s;printf("a=");scanf("%d", &a);printf("b=");scanf("%d", &b);s = a-b;printf("a-b=%d\\n", s);system("pause");return 0;} 运行结果:...

求C语言大神来编个程序呀。。。
设白皮有x块,则黑皮有(32-x)块,每块白皮是六边形,共6x条边,因每块白皮有三条边和黑皮连在一起,故黑皮共有3x条边,可得方程3x=5(32-x);所以:include"stdio.h"main(){ int x; for(x=1;x<32;x++) if(3*x==5*(32-x)) printf("黑皮块有%d块,白皮块有%d块!

求C语言高手编写一个简单的源程序7小妹刚开始自学C语言,菜鸟一个,希 ...
首先你要要想明白,程序里每个变量表示的内容,第1问其实就是考你返回值的写法和变量n的含义,变量n当然就是桃子的数量了,所以第1个空就是 return n 第2问其实是考你调用函数的写法,注意传入参数和结果赋给一个变量,所以第2个空就是 n= fun(day)最好再上机调试一下,建议拿到一个题目,尽量...

求大神帮忙,帮我编一个C语言程序
int sum(int a,int b){return a+b;} int main(){int a,b,c;srand(time(0));a = rand()%100+1;b = rand()%100+1;printf("%d+%d=",a,b);scanf("%d",&c);while(c-sum(a,b)){printf("Not correct! Try againt!\\n");printf("%d+%d=",a,b);scanf("%d",&c);} ...

大神来帮忙用c语言编个程序啊!
int year, month, day, sum = 0, leap;printf("please input year,month,day\\n");scanf("%d, %d, %d", &year, &month, &day);if(day > 0 && day < 32 && month < 13 && month > 0){ enum data {d1 = 1, d2, d3, d4, d5, d6, d7, d8, d9, d10, d11, d...

求C语言大神帮忙编写一个程序,按要求写出来。
void rotate( int (*arrA)[MAX], int (*arrB)[MAX], int m, int n);int main(void){ int arrA[MAX][MAX], arrB[MAX][MAX], i, j, m, n;printf("请输入 m n: ");scanf("%d %d", &m, &n);printf("请输入 %d 行 %d 列矩阵:\\n", m, n);for (i=0; i<m; i...

c语言程序大神帮忙设计一下?
1、实现文件写入功能,一次写入一个职工信息。2、实现查询功能(包含4种条件查询)。3、实现信息删除和修改并写入文件。根据题意,数据用结构数组存储,且职工编号唯一性,因此单独两个函数计算信息长度和编号。除条件查询函数和读取文件的函数,不会自行free释放内存。如你写代码调用,注意自行写free语句释放...

大神,快点帮我写一下这个C语言程序,谢谢。第五题。
include <stdio.h> int main(){ char a[]="abc23d45f6";char b[20];int i,j=0;for(i=0;(a[i])!='\\0';i++){if (a[i]>=48 &&a[i]<=57){b[j]=a[i];j++;} } for(i=0;i<j;i++)printf("%4c",b[i]);getch();} ...

一道c语言编程,求大神
p, int n){int i;for (i = 0; i < n; ++i){printf ("%d ", *(p + i));}printf ("\\n");}#define N 10int main(int argc, char** argv){ int arr[N], i;printf ("请输入 %d 个整数:\\n", N);for (i = 0; i < N; ++i){scanf ("%d", &arr[i])...

相似回答
大家正在搜