Thread: Different outputs on different OS

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Oct 2010
    Posts
    19

    Unhappy Different outputs on different OS

    Hello all. this is a great site for programming and thanks for all people who help. so am writing a C program in linux using gcc and gedit. the program is not yet completed. and i am short of time. the program output varies from OS to OS. the main role of the program is to encrypt a file after the user has input a text and saved it to a file. the text that is saved to the file contains no text when run in linux. when run in windows xp i get the text followed by a square. in windows 7 i get a clean text file. i wonder if someone can point me to the right direction. heres the code. am still a beginner. thanks in advance. You can go directly to the function newFile() which is the part that writes to a file

    Code:
    #include <stdio.h>
    #include <string.h>
    
    
    #define TEXTSIZE 256
    
    //Function Prototypes//
    
    void optionLists();
    void encryption();
    void decryption();
    void encryptionLists();
    void newFile();
    
    //Global Variables//
    
    char *line = {"\n-----------------------\n"};
    char *newline = "\n";
    short int choice;
    
    
    int main()
    {
        optionLists();
        printf(" Enter Choice: ");
        scanf( "%d", &choice);
    
        switch (choice)
        {
            case 0:
            {
                return 0;
                break;
            }
    
            case 1:
            {
                encryption();
                break;
            }
    
            case 2:
            {
                decryption();
                break;
            }
    
            default:
            {
                printf(line);
                printf(" Wrong Choice!\n");
            }
        }
    
    
    }
    
    void optionLists()
    {
        printf(" [1] Encryption\n");
        printf(newline);
        printf(" [2] Decryption\n");
        printf(newline);
        printf(" [0] Exit\n");
        printf(line);
    }
    
    
    void encryption()
    {
        printf(" E N C R Y P T I O N   M E N U\n");
        encryptionLists();
        getchar();
    }
    
    
    void decryption()
    {
        printf(" \nD E C R Y P T I O N   M E N U\n");
        getchar();
    
    }
    
    void encryptionLists()
    {
        printf(newline);
        printf(" [1] Existing File\n");
        printf(newline);
        printf(" [2] New File\n");
        printf(line);
        printf(" Enter Choice: ");
        scanf( "%d", &choice);
    
        switch (choice)
        {
            case 1:
            {
                printf("Test");
                break;
    
            }
    
            case 2:
            {
                newFile();
                break;
    
            }
    
        }
    
    
        getchar();
    }
    
    
    void newFile()
    {
        FILE *fp;
        char text[TEXTSIZE];
        int i, wordCount;
        printf(newline);
        printf(" N E W   F I L E\n");
        char filename[20];
        //char fileName[25];
        //char ext_1 = '.';
        //char ext_2 = 't';
        //char ext_3 = 'x';
        //char ext_4 = 't';
        //char ext[5] = "";
    
        //sprintf(ext, "%c%c%c%c",ext_1,ext_2,ext_3,ext_4);
    
    
        printf(line);
        printf(newline);
        printf(" Enter the name of the file: ");
        scanf("%s", &filename);
        //strcat(fileName, filename);
        //strcat(fileName, ext);
        fp = fopen(filename, "ab+");
    
        if (fp == NULL)
        {
           printf(" New file failed");
           getchar();
        }
    
        else
        {
            printf(" Enter your text below:\n");
    
            for (i = 0; i < TEXTSIZE; i++)
            {
                scanf("%c", &text[i]);
                printf("%s\n", text);
    
            }
    
    
            fp = fopen(filename, "ab+");
    
            if (fp != NULL)
            {
    
                fflush(stdin);
                fgets(text, TEXTSIZE, stdin);
                fputs(text,fp);
                fclose(fp);
            }
    
            else
            {
                printf("\nCould not create file!\n");
            }
    
    
            getchar();
    
        }
    
    
    }
    Last edited by darksifer; 10-19-2010 at 10:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OS: How does it work?
    By GReaper in forum Tech Board
    Replies: 15
    Last Post: 08-27-2010, 01:41 PM
  2. detectine OS type?
    By techevo in forum C Programming
    Replies: 4
    Last Post: 03-12-2010, 05:09 AM
  3. Detecting if OS is Windows???
    By Ktulu in forum Windows Programming
    Replies: 2
    Last Post: 11-19-2006, 02:49 AM
  4. a simple OS
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 06-06-2004, 10:47 PM
  5. How do they compile code for an OS ?
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 49
    Last Post: 03-28-2002, 12:16 AM

Tags for this Thread