Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C
#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); 
}


[Edit - formatting and changed tag from C++ to C]
Posted
Updated 21-Mar-10 20:03pm
v2

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.
 
Share this answer
 
What exactly is the error and what are you trying to do here? Please be specific.


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


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"
 
Share this answer
 
v3
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900