C programming help

hecker_thama

Well-known member
  • Dec 27, 2022
    6,764
    6,977
    113
    C:
    #include<stdio.h>
    
    int main()
    {
        char buffer[255];
        FILE *pF = fopen("poem.txt", "w");
        fprintf(pF, "Once there was an elephant,\nWho tried to use the telephant—\nNo! No! I mean an elephone\nWho tried to use the telephone—\n\n(Dear me! I am not certain quite\nThat even now I’ve got it right.)\nHowe’er it was, he got his trunk\nEntangled in the telephunk;\n\nThe more he tried to get it free,\nThe louder buzzed the telephee—\n(I fear I’d better drop the song\nOf elephop and telephong!))\n");
       
        char poem;
        printf("Do you need a read poem again?(N/y) ");
        scanf("%c", &poem);
        if(poem == 'y' || poem == 'Y'){
            FILE *read = fopen("poem.txt", "r");
            printf("Here is your poem---->\n");
            //char buffer[255];
            while(fgets(buffer, 255, read)){
            printf("%s", buffer);
            }
            fclose(read);
        }
        else if(poem == 'N'){
            printf("Poem is saved!");
        }
    
        fclose(pF);
        return 0;
    }

    file eka create unata read wenne nane
     

    hecker_thama

    Well-known member
  • Dec 27, 2022
    6,764
    6,977
    113
    C:
    #include<stdio.h>
    
    int main()
    {
        char buffer[255];
        FILE *pF = fopen("poem.txt", "w");
        fprintf(pF, "Once there was an elephant,\nWho tried to use the telephant—\nNo! No! I mean an elephone\nWho tried to use the telephone—\n\n(Dear me! I am not certain quite\nThat even now I’ve got it right.)\nHowe’er it was, he got his trunk\nEntangled in the telephunk;\n\nThe more he tried to get it free,\nThe louder buzzed the telephee—\n(I fear I’d better drop the song\nOf elephop and telephong!))\n");
      
        char poem;
        printf("Do you need a read poem again?(N/y) ");
        scanf("%c", &poem);
        if(poem == 'y' || poem == 'Y'){
            FILE *read = fopen("poem.txt", "r");
            printf("Here is your poem---->\n");
            //char buffer[255];
            while(fgets(buffer, 255, read)){
            printf("%s", buffer);
            }
            fclose(read);
        }
        else if(poem == 'N'){
            printf("Poem is saved!");
        }
    
        fclose(pF);
        return 0;
    }

    file eka create unata read wenne nane
    den wada
    C:
    #include<stdio.h>
    
    int main()
    {
        char buffer[255];
        FILE *pF = fopen("poem.txt", "w");
        fprintf(pF, "Once there was an elephant,\nWho tried to use the telephant—\nNo! No! I mean an elephone\nWho tried to use the telephone—\n\n(Dear me! I am not certain quite\nThat even now I’ve got it right.)\nHowe’er it was, he got his trunk\nEntangled in the telephunk;\n\nThe more he tried to get it free,\nThe louder buzzed the telephee—\n(I fear I’d better drop the song\nOf elephop and telephong!))\n");
        
        fclose(pF);
        char poem;
        printf("Do you need a read poem again?(N/y) ");
        scanf("%c", &poem);
        if(poem == 'y' || poem == 'Y'){
            FILE *read = fopen("poem.txt", "r");
            printf("Here is your poem---->\n");
            //char buffer[255];
            while(fgets(buffer, 255, read)){
            printf("%s", buffer);
            }
            fclose(read);
        }
        else if(poem == 'N'){
            printf("Poem is saved!");
        }
    
        //fclose(pF);
        return 0;
    }
     

    amino

    Well-known member
  • Jul 27, 2008
    2,312
    2,780
    113
    Pilimathalawa
    #include <stdio.h>

    int main() {
    FILE *fp;
    char ch;

    fp = fopen("example.txt", "r"); // open the file in read mode

    if (fp == NULL) {
    printf("Error: Unable to open file\n");
    return 1;
    }

    while ((ch = fgetc(fp)) != EOF) { // read and display the contents of the file
    putchar(ch);
    }

    fclose(fp); // close the file

    return 0;
    }