Thread: Comparing and integer variable with a char variable.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Sep 2011
    Posts
    8

    Comparing and integer variable with a char variable.

    Hello People! I hope everything's well...
    Im a noob coder and I have the next question,

    Here's my code, it copies character by character to another file.
    Code:
    #include <stdio.h>int main (int argc, char *argv[])
    {
    
    
      char caracter;
    char encrypt;
      char *archivaldo[20];
      int cont;
      FILE *fp;
      FILE *fp2;
    
    
    
    
      if((fp=fopen(argv[1], "r"))==NULL)
        {
          printf("no se puede abrir");
        }
      else
        {
          printf("si se pudo abrir");
          fp2=fopen(argv[2], "w");
        }
    
    
      while((caracter=getc(fp))!=EOF)
        {
    
    
    ////I want to take the caracter's ASCII value and save it to another variable, how can I do that?////
          putc(caracter, fp2);
        }
    
    
      fclose(fp);
      fclose(fp2);
      
    }
    }

    How In earth can I take the ASCII value of the 'caracter' variable and save it on another variable, let me remind you that the 'caracter' is always changing, you never know which letter its going to get.

    If you need any more info, Im glad to give it.

    Thank you for helping me out & taking the time to read.

    ****Btw(on a further note) I want to print on the second file as backwards, for example you read "Hello" I want it to be printed on another file as "olleH" I know you have to use LIFO structures, I know this may not be the place but can someone explain how to use this kind of structure?

    ///////////EDITTTTT////////
    Ok, So, let me explain myself.


    *Im reading the file character by character because I want to encrypt it using the ASCII values.


    for example I've read a character 'R' which I believe is 82

    I want ascii_variable=82///Its not going to be 'R' always, depends on the file.

    How can I save the ascii value on to the variable ascii_variable...how is this possible?

    //////////More EDITTTT////////////////////////////


    Also, I want to take that ascii value and find the character that it is.

    For example

    ascii_variable=82

    character_variable = ascii_variable interpretation (in this case 'R')

    How In earth can I do this!!!!
    Last edited by XIIIX; 09-19-2011 at 12:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 09-04-2011, 09:29 PM
  2. What does it mean when a integer variable has a word value
    By Nathan the noob in forum C++ Programming
    Replies: 2
    Last Post: 06-26-2008, 02:44 AM
  3. Comparing integer char[] elements
    By ccflyer in forum C Programming
    Replies: 7
    Last Post: 04-20-2008, 03:40 PM
  4. How many bits are '1' in an integer variable?
    By cuthbert in forum C Programming
    Replies: 51
    Last Post: 09-13-2006, 04:14 PM
  5. How many bits are '1' in an integer variable?
    By cuthbert in forum C++ Programming
    Replies: 0
    Last Post: 09-12-2006, 01:08 PM

Tags for this Thread