help! program compiles but won't run

This is a discussion on help! program compiles but won't run within the C Programming forums, part of the General Programming Boards category; I sucessfully compiled it under linux and windows it works under linux but under windows it gives an error when ...

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    16

    help! program compiles but won't run

    I sucessfully compiled it under linux and windows it works under linux but under windows it gives an error when I run it.

    Code:
    #include <stdio.h>
    
    int main(int argc,char* argv[]){
    
      FILE *fin,*fout;
      int c;
      char key[]={(int)argv[3]}; 
      
    if ((fin=fopen(argv[1],"r"))==NULL){
        printf("\nERROR\n");
        return 0;
          }
    
      fout=fopen(argv[2],"w");
    
      while((c=fgetc(fin))!=EOF){
        c=c^key[0];
        fputc(c,fout);
      }
    
      fclose(fin);
      fclose(fout);
      
      return 0;
    }

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    You can get it to compile by changing the following bits, but even so, I don't think it's doing what you're intending it to (and it's not safe anyway).

    >char key[]={(int)argv[3]};
    Change this to:
    >char key = argv[3][0];

    >c=c^key[0];
    Change this to:
    >c=c^key;

    Do some error checking to ensure the user has provided three valid arguments, before you start indexing the argv array. Thats what I mean by "safe".

    I presume the 3rd parameter is a string key used to encrypt the file? At present you are only using the first character. There's a stack of example source for xor encryption, but if you get stuck, post again.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 01:42 AM
  2. Help on making program run more efficiently
    By peeweearies in forum C Programming
    Replies: 2
    Last Post: 03-23-2009, 02:01 AM
  3. Client-server system with input from separate program
    By robot-ic in forum Networking/Device Communication
    Replies: 3
    Last Post: 01-16-2009, 02:30 PM
  4. Make a program run at startup
    By cookie in forum Tech Board
    Replies: 2
    Last Post: 06-08-2007, 08:36 PM
  5. Help me with my basic program, nothing I create will run
    By Ravens'sWrath in forum C Programming
    Replies: 31
    Last Post: 05-13-2007, 02:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21