Need help with small code change

This is a discussion on Need help with small code change within the C Programming forums, part of the General Programming Boards category; I'm trying to rewrite another persons code and got stuck on this part. I need to change this part and ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    3

    Need help with small code change

    I'm trying to rewrite another persons code and got stuck on this part.
    I need to change this part and not have "s" as a pointer.

    Code:
    char tmp[100];
    unsigned char *s;
    
    s = (unsigned char *)tmp;
    
    while (*s)
      {
      char c;
      c= *s++;
      }
    It was a while ago that I wrote c-code, so is there someone who can help me?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,271
    Use an array index instead.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    3
    Quote Originally Posted by laserlight View Post
    Use an array index instead.
    A while ago since i wrote c-code regularly = about 10 years
    I'm not sure what's being done but gave it a shot... Would this work/do the same for example?

    Code:
    char tmp[100];
    unsigned char s;
    
    for (i=0;i<strlen(tmp);i++)
      {
      char c;
      s = (unsigned char)tmp[i];
      c = s;
      }

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    What are you trying to do?

  5. #5
    Registered User
    Join Date
    Aug 2009
    Location
    Sweden
    Posts
    3
    Solved. (Got help testing it from a friend that had VS installed. I don't have it on this computer) This works the same:

    Code:
    char tmp[100];
    int i;
    for (i=0;i<strlen(tmp);i++)
    {
    char c;
    c = (unsigned char)tmp[i];
    }
    It was small pieces of a password encryption function. I needed to rewrite it in C#, but wasn't sure about how that small part worked.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. small code question
    By nigy in forum C++ Programming
    Replies: 12
    Last Post: 04-03-2005, 01:42 PM
  2. Need help with C program
    By ChrisH in forum C Programming
    Replies: 38
    Last Post: 11-13-2004, 01:11 AM
  3. True ASM vs. Fake ASM ????
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 04-02-2003, 04:28 AM
  4. Any tool to change c++ code into c code?
    By crliu in forum C++ Programming
    Replies: 3
    Last Post: 12-09-2002, 09:44 AM
  5. how do you change the ctrl+C exit code?
    By Golden Bunny in forum Windows Programming
    Replies: 0
    Last Post: 04-09-2002, 03:18 PM

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