Crush My Programm

This is a discussion on Crush My Programm within the C Programming forums, part of the General Programming Boards category; /* Name : CRYPT Author : KRAKZ Email : Krakz@email.it WEB : http://krakz.tk Date : 20/02/03 9.03 Description: CRITTOGRAFIA (SOLO ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    44

    Angry Crush My Programm

    /*
    Name : CRYPT
    Author : KRAKZ
    Email : Krakz@email.it
    WEB : http://krakz.tk
    Date : 20/02/03 9.03
    Description: CRITTOGRAFIA (SOLO STRINGHE)
    LICENZA : GNU|GPL
    */



    # include <stdio.h>
    # include <string.h>
    # include <stdlib.h>
    # define MAX 255

    int main (void)
    {
    int i, I = 0 , countchiave , countfrase , crypt[MAX] ;
    char chiave[MAX] , nomefile[10] , salva[MAX] , frase[MAX];
    FILE *cfPtr , *cryp ;





    printf ("Open File\n") ;
    gets(nomefile) ;
    printf ("Enter KEY\n") ;
    gets(chiave) ;
    printf ("Save as\n") ;
    gets(salva) ;

    if ((cryp = fopen(salva , "a")) == NULL)
    printf("File is open\n");


    if ((cfPtr = fopen(nomefile , "r")) == NULL)
    printf("file is open\n");

    while (!feof(cfPtr))
    {
    fscanf (cfPtr , "%c" , frase[i] ) ;
    printf ("%c" , frase[i] );
    i = i + 1 ;

    /* VERIFICA LA LUNGHEZZA DELLE STRINGHE */
    countchiave = strlen(chiave) ;

    for ( i = 0 ; countfrase > i ; i++)
    {

    if ( countchiave < I) I = 0 ;;

    crypt[i] = chiave[I] + frase[i] ;



    if ( crypt[i] < 100 ) fprintf(cryp, "0" ) ;;



    fprintf (cryp , "%d", crypt[i] );



    I = 1 + I ;
    }
    }

    printf ("Il file testo stato cryptato , per decryptarlo\n") ;
    system("PAUSE");

    }

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    It's written in..erhm... at least not english so i cant read the
    variables name's, purpose's nor the comments.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    44
    scuse me , i dont remember
    http://linuxdesktop.it

  4. #4
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Crush My Programm
    Eh?

    Is something wrong with it? Errors? What do you mean by crush?
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Don't use the gets() function, use instead fgets().

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    44
    Code:
    /* 
    Name       : CRYPT 
    Author     : KRAKZ 
    Email      : Krakz@email.it
    WEB        : http://krakz.tk
    Date       : 20/02/03 9.03 
    Description: CRYPT FILE
    LICENZA    : GNU|GPL 
         */ 
    
     
    
    # include <stdio.h> 
    # include <string.h> 
    # include <stdlib.h> 
    # define MAX 255 
    
    int main (void) 
    { 
       int i, I = 0 , countkey , countphrase , crypt[MAX]  ; 
    
       char key[MAX] , namefile[10] , save[MAX] , phrase[MAX];
      
       FILE *cfPtr , *cryp ;
    
    
    
          
          
      printf ("Open File\n")  ;
      gets(namefile) ;
    
      printf ("Enter key\n") ; 
      gets(key) ;
     
      printf ("save as\n")  ;
      gets(save) ;
    
      if ((cryp = fopen(save , "a")) == NULL)  
                               printf("File is open\n");
                               
    
     if ((cfPtr = fopen(namefile , "r")) == NULL) 
                                   printf("File is open\n");
    
               while (!feof(cfPtr))
               {
     
                 fscanf (cfPtr , "%c" , phrase[i] ) ;
                
                 printf ("%c" , phrase[i] );
      
                  i = i + 1 ;
     
                 countkey = strlen(key) ; 
    
                            
    
                               for ( i = 0 ; countphrase > i ; i++) 
                              { 
    
                                 if ( countkey < I)  I = 0 ;;   
    
                                crypt[i] = key[I] + phrase[i] ;           
    
                                if ( crypt[i] < 100 )    fprintf(cryp, "0" ) ;;   
                                                                                                          
                                fprintf (cryp , "%d",  crypt[i] );                                
    
    
    
                                I = 1 + I ;                                      
                              }
    
    
                  } 
    
      printf ("END\n") ; 
      system("PAUSE");                         
    
    }
    http://linuxdesktop.it

  7. #7
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,386
    > What do you mean by crush?

    I think he means crash, his program is probably crashing.

    Krakz, could you give some more information? Where does it crash? What does it now and what should it do?

    Code:
    if ((cryp = fopen(save , "a")) == NULL)  
      printf("File is open\n");
    
    if ((cfPtr = fopen(namefile , "r")) == NULL) 
      printf("File is open\n");
    That is not correct. If fopen() returns NULL, it means the file is not opened and the program should perform some error-handling. Also note that if opening cfPtr failed, then opening cryp succeeded, don't forget to close cryp in the error-handling.

    You should initialise variable i before using it.

    Code:
    countkey = strlen(key);
    You don't need to do this each time you cycle through your loop, the string key does not change.

    You must close your files, with fclose(), when you are done.

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    44
    Attached Images Attached Images  
    http://linuxdesktop.it

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Error handling on your fopen()'s (as already mentioned. Implement this before going any futher. Do it for all files that you open.
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    
    if ((cryp = fopen(salva , "a")) == NULL) 
    {
        perror(salva);
        return EXIT_FAILURE;
    }
    
    printf("File is open\n");
    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. HexDump Programm....
    By Kdar in forum C Programming
    Replies: 4
    Last Post: 10-03-2006, 05:13 AM
  2. programm will not start
    By keeper in forum C++ Programming
    Replies: 11
    Last Post: 07-03-2006, 06:02 AM
  3. printing with a c programm
    By -11Reaper11- in forum C++ Programming
    Replies: 3
    Last Post: 04-30-2006, 10:31 AM
  4. windowsAPI programm
    By datainjector in forum Windows Programming
    Replies: 8
    Last Post: 03-11-2003, 10:08 PM
  5. I am looking for a programm!
    By Unregistered in forum C Programming
    Replies: 1
    Last Post: 04-10-2002, 11:51 AM

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