帮助我找到错误n请给我正确的代码. [英] help me find error n plz give me the correct code.

查看:103
本文介绍了帮助我找到错误n请给我正确的代码.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include "stdafx.h"
#include "stdio.h"
#include "string.h"

main() {
    FILE *fp;
    char str[100],filename[10]; 
    int i=0;

    if((fp=fopen("test","w"))==NULL) {
        printf("cannot open the file\n"); 
        return 0; 
    }
    printf("please input a string:\n");
    gets(str); 
    while(str!=NULL) {
        if(str>=a&&str<=z) 
            str=str-32;
        fputc(str,fp); 
        i++; 
    } 
    fclose(fp);
    fp=fopen("test","r");
    fgets(str,strlen(str)+1,fp);
    printf("%s\n",str);
    fclose(fp); 
}





推荐答案

我们可能会帮助您发现错误.一旦找到它们,便可以对其进行修复,因此,没有理由为您提供正确的代码-您已经拥有了它.

我建议您格式化代码,以使其更易于阅读和更多地使用空格.我对您的帖子进行了一定程度的编辑,但仍可以改进.

现在,您需要编辑问题,以便可以告诉我们您正在处理的错误,了解的信息以及为解决该问题所做的工作.

您的代码中存在多个错误,但是您一次只能处理一个错误.
We may help you find your errors. Once you find them, you will be able to fix them, so there will be no reason to give you the correct code - you will have it already.

I would suggest that you format your code so that it is easier to read and make more use of whitespace. I edited your post to some extent, but it could still use improvement.

Now you need to edit your question, so that you can tell us what error you are getting that you are working on, what information you have about it, and what you have done to try to solve it.

There is more than 1 error in your code, but you need to take them one at a time.


错误的确切含义是什么,您打算在这里做什么?请具体说明.


What exactly is the error and what are you trying to do here? Please be specific.


henryBcFc写道:
henryBcFc wrote:

while(str!= NULL){
if(str> = a& str< = z)
str = str-32;
fputc(str,fp);
i ++;
}

while(str!=NULL) {
if(str>=a&&str<=z)
str=str-32;
fputc(str,fp);
i++;
}



看起来您想将所有输入字符都转换为大写并将其打印在文件中.
您需要在循环内使用"str [i]"而不是"str"



Looks like you want to convert all the input characters to upper case and print it in a file.
You need to use "str[i]" inside the loop instead of "str"


我怀疑您认为这是C ++.不是.它真的很丑陋.也许您需要告诉我们为什么您不使用C ++,或者您是否知道您正在使用C,然后告诉我们您想做什么以及在哪里进行操作"卡住了.
I suspect that you think this is C++. It''s not. It''s really ugly C. Perhaps you need to tell us why you''re not using C++, or if you know you''re using C, and then tell us what you''re trying to do, and where you''re stuck.


这篇关于帮助我找到错误n请给我正确的代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆