Hey guys,
I am new to programming in C, I am trying to save "tc" into a variable using for loops. I understand for integers, multiply the result by 10. Is there a similar way to do this for chars?
For integers,
for(j = 0; j < i; j++)
{
int digit = line[j] - '0';
start_number = 10 * start_number + digit;
}
For chars,
#include <stdio.h>
#include <string.h>
int main(int argc, char *argv[])
{
char line[] = "ta/tb/tc";
int i, j;
char a;
line[strlen(line) - 1] = 0;
// find backslash going in reverse
for(i = strlen(line); i > 0; i--)
{
if(line[i]=='/') break;
}
printf("%d\n", i);
// Find tc
for(j = i + 1; j < strlen(line); j++)
{
printf("%c\n", line[j]);
}
return 0;
}