I'm really new to C Programming. We have an assignment where the program is supposed to accept a string input, and "decode it". So, if the user enters in 3a4g5s at the prompt, the output will be AAAGGGGSSSSS, for example. I elected to do this with for loops. This is my encode function:

Code:
void decode(char *ostr, int lenght)
{
  char nstr[lenght];  //new shortened copy of the string
  int char1; //temporary character
  int lcv = 0; //loop control variable
  int lcv2 = 0; //loop control variable
  int counter = 0; //counter variable
  int counter2 = 0;

  strcpy(nstr, ostr);

  char1 = nstr[1];
  counter = (int)nstr[0];

  for(lcv = 2; lcv <= lenght; lcv=lcv+2)
  {
    for(lcv2=0; lcv2 < counter; lcv2++)
    {
      printf("%c", toupper(char1));
    }
    char1 = nstr[lcv+1];
    counter = (int)nstr[lcv];
  }
  printf("\n");
}
Now, the problem with this is that when it scans in a value for counter, it is scanning in the ASCII value of the number, rather than the number itself. I don't know how to force it to pull the number out of the string.

My thought was to use sscanf, where the command would be:
Code:
  sscanf(nstr, "%d", &counter);
The problem with this is that even in the for loop, it will only keep grabbing the first number in the string, rather than moving down the string as the for loop increments. Does anyone here have any suggestions?