简单C语言编程问题!!急!!
要求:从磁盘读入一个字符串,将指定小写字母全部转换成大写字母,然后输出到一个磁盘文件“test.txt”中保存。1.逆序输出2.大写字母不作处理3.单个小写字符转换大写(...
要求:
从磁盘读入一个字符串,将指定小写字母全部转换成大写字母,然后输出到一个磁盘文件“test.txt”中保存。
1. 逆序输出
2. 大写字母不作处理
3. 单个小写字符转换大写 (a->A)
4. 指针操作
5. 统计字符串长度
这是我写的代码,能够运行,但却没有结果......
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[])
{
char descrip[MAXNUM];
double price;
FILE *inFile;
int count=0;
inFile=fopen("D://test.txt","r");
if (inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(descrip,MAXNUM,inFile) !=NULL)
{
printf("%s ",descrip);
}
count=function_1(descrip);
function_2(descrip);
function_3(descrip);
printf("%d",count);
fclose(inFile);
return 0;
}
int function_1 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++;
}
return (i);
}
void function_2 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>='a'&&*pt<='z')
*pt=*pt-32;
pt++;
}
}
void function_3 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++;
}
while(i==0)
{
printf("%c",descrip[i]);
i--;
}
}
初学...希望各位大神能在此程序中修改......谢谢
这是要求编辑的文段.....刚忘了贴出来
Eternal truths will be neither true nor eternal unless they have fresh meaning for every new social situation. (Franklin Roosevelt , American president) 展开
从磁盘读入一个字符串,将指定小写字母全部转换成大写字母,然后输出到一个磁盘文件“test.txt”中保存。
1. 逆序输出
2. 大写字母不作处理
3. 单个小写字符转换大写 (a->A)
4. 指针操作
5. 统计字符串长度
这是我写的代码,能够运行,但却没有结果......
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[])
{
char descrip[MAXNUM];
double price;
FILE *inFile;
int count=0;
inFile=fopen("D://test.txt","r");
if (inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(descrip,MAXNUM,inFile) !=NULL)
{
printf("%s ",descrip);
}
count=function_1(descrip);
function_2(descrip);
function_3(descrip);
printf("%d",count);
fclose(inFile);
return 0;
}
int function_1 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++;
}
return (i);
}
void function_2 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>='a'&&*pt<='z')
*pt=*pt-32;
pt++;
}
}
void function_3 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++;
}
while(i==0)
{
printf("%c",descrip[i]);
i--;
}
}
初学...希望各位大神能在此程序中修改......谢谢
这是要求编辑的文段.....刚忘了贴出来
Eternal truths will be neither true nor eternal unless they have fresh meaning for every new social situation. (Franklin Roosevelt , American president) 展开
6个回答
展开全部
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[])
{
char descrip[MAXNUM];
double price;
FILE *inFile;
int count=0;
inFile=fopen("test.txt","r"); //直接将文件放在工程目录下就行
if (inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(descrip,MAXNUM,inFile) !=NULL) //这是从文件中读取字符串,而你题目要求要写到test.txt
{
printf("%s ",descrip);
}
fclose(inFile);
count=function_1(descrip);
printf("\n字符串长度:%d\n",count);
function_2(descrip);
printf("转换后的字符串:%s\n",descrip);
function_3(descrip);
printf("逆序输出: %s\n",descrip);
FILE *fp;
if((fp=fopen("testoutput.txt","w+"))==NULL)
{
printf("can't open the file!");
exit(0);
}
fputs(descrip,fp);
fclose(fp);
printf("已经输出到文件!\n");
return 0;
}
int function_1 (char *descrip) //假设你这个是统计的函数
{
return strlen(descrip);
}
void function_2 (char *descrip) //假设你这个是小写变大写的函数
{
int i=0;
for(i=0;i<strlen(descrip);i++)
{
if(descrip[i]>='a'&&descrip[i]<='z')
descrip[i]=descrip[i]-32;
}
}
void function_3 (char *descrip) //假设你这个是逆序输出的函数
{
int i=0;
int temp=0;
for(i=0;i<strlen(descrip)/2;i++)
{
temp=descrip[i];
descrip[i]=descrip[strlen(descrip)-i-1];
descrip[strlen(descrip)-i-1]=temp;
}
}
#include <stdlib.h>
#include <string.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[])
{
char descrip[MAXNUM];
double price;
FILE *inFile;
int count=0;
inFile=fopen("test.txt","r"); //直接将文件放在工程目录下就行
if (inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(descrip,MAXNUM,inFile) !=NULL) //这是从文件中读取字符串,而你题目要求要写到test.txt
{
printf("%s ",descrip);
}
fclose(inFile);
count=function_1(descrip);
printf("\n字符串长度:%d\n",count);
function_2(descrip);
printf("转换后的字符串:%s\n",descrip);
function_3(descrip);
printf("逆序输出: %s\n",descrip);
FILE *fp;
if((fp=fopen("testoutput.txt","w+"))==NULL)
{
printf("can't open the file!");
exit(0);
}
fputs(descrip,fp);
fclose(fp);
printf("已经输出到文件!\n");
return 0;
}
int function_1 (char *descrip) //假设你这个是统计的函数
{
return strlen(descrip);
}
void function_2 (char *descrip) //假设你这个是小写变大写的函数
{
int i=0;
for(i=0;i<strlen(descrip);i++)
{
if(descrip[i]>='a'&&descrip[i]<='z')
descrip[i]=descrip[i]-32;
}
}
void function_3 (char *descrip) //假设你这个是逆序输出的函数
{
int i=0;
int temp=0;
for(i=0;i<strlen(descrip)/2;i++)
{
temp=descrip[i];
descrip[i]=descrip[strlen(descrip)-i-1];
descrip[strlen(descrip)-i-1]=temp;
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
/*
Some are born great, some achieve greatness,and some have greatness thrust upon them.
.MEHT NOPU TSURHT SSENTAERG EVAH EMOS DNA,SSENTAERG EVEIHCA EMOS ,TAERG NROB ERA EMOS
85
Press any key to continue
*/
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[]) {
char descrip[MAXNUM];
FILE *inFile;
int count = 0;
inFile = fopen("F:\\VC\\malvolio.txt","r");
if(inFile == NULL) {
printf("\nFailed to open the file.\n");
exit(1);
}
while(fgets(descrip,MAXNUM,inFile) != NULL) {
printf("%s\n",descrip);
}
count = function_1(descrip);
function_2(descrip);
function_3(descrip);
printf("%d\n",count);
fclose(inFile);
return 0;
}
int function_1(char *descrip) { // 返回串长度 int len;
char *p = descrip;
for(len = 0; *p; len++,p++);
return len;
}
void function_2 (char *descrip) { // 将小写字母转换为大写 int i;
char *p = descrip;
for(i = 0; *p; ++i,++p)
if(*p >= 'a' && *p <= 'z')
*p -= 32;
}
void function_3(char *descrip) { // 倒叙输出串 descrip
int i,len = function_1(descrip);
char *p = descrip;
for(i = len - 1; i >= 0; --i)
printf("%c",p[i]);
printf("\n");
}
Some are born great, some achieve greatness,and some have greatness thrust upon them.
.MEHT NOPU TSURHT SSENTAERG EVAH EMOS DNA,SSENTAERG EVEIHCA EMOS ,TAERG NROB ERA EMOS
85
Press any key to continue
*/
#include <stdio.h>
#include <stdlib.h>
#define MAXNUM 10000
int function_1 (char *);
void function_2 (char *);
void function_3 (char *);
int main(int argc, char *argv[]) {
char descrip[MAXNUM];
FILE *inFile;
int count = 0;
inFile = fopen("F:\\VC\\malvolio.txt","r");
if(inFile == NULL) {
printf("\nFailed to open the file.\n");
exit(1);
}
while(fgets(descrip,MAXNUM,inFile) != NULL) {
printf("%s\n",descrip);
}
count = function_1(descrip);
function_2(descrip);
function_3(descrip);
printf("%d\n",count);
fclose(inFile);
return 0;
}
int function_1(char *descrip) { // 返回串长度 int len;
char *p = descrip;
for(len = 0; *p; len++,p++);
return len;
}
void function_2 (char *descrip) { // 将小写字母转换为大写 int i;
char *p = descrip;
for(i = 0; *p; ++i,++p)
if(*p >= 'a' && *p <= 'z')
*p -= 32;
}
void function_3(char *descrip) { // 倒叙输出串 descrip
int i,len = function_1(descrip);
char *p = descrip;
for(i = len - 1; i >= 0; --i)
printf("%c",p[i]);
printf("\n");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
nFile=fopen("test.txt","r");
if (inFile==NULL)
{
printf("\nFailed to open the file.\n");
exit(1);
}
while (fgets(descrip,MAXNUM,inFile) !=NULL)
{
printf("%s ",descrip);
}
fclose(inFile);
count=function_1(descrip);
printf("\n字符串长度:%d\n",count);
function_2(descrip);
printf("转换后的字符串:%s\n",descrip);
function_3(descrip);
print" %s\n",descrip
FILE *fp;
if((fp=fopen("testoutput.txt","w+"))==NULL)
{
printf("can't open the file!");
exit(0);
}
fputs(descrip,fp);
fclose(fp);
printf
return 0;
}
int function_1 (char *descrip)
{
return strlen(descrip);
}
void function_2 (char *descrip)
{
pt++
int function_1(char *descrip) {
求采纳求采纳求采纳求采纳求采纳求采纳求采纳求采纳求采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
两个问题:
1.
int function_1 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++; //这里少了对pt指针的操作,应该加上pt++;
}
return (i);
}
2.
没有看到你往文件中写数据的操作。
1.
int function_1 (char *descrip)
{
int i=0;
char *pt;
pt=descrip;
while (pt!=NULL)
{
if(*pt>=' '&&*pt<='z')
i++; //这里少了对pt指针的操作,应该加上pt++;
}
return (i);
}
2.
没有看到你往文件中写数据的操作。
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
int function_1 这个函数while死循环了,你的指针没有做移动
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询