Thread: Need help with small code change

  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
    28,413
    Use an array index instead.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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, 12: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, 02:18 PM