I began working out a problem and ran into a brain freeze and I eventually solved it, but it doesn't look like what I originially had in mind. The results are perfect, I will keep the code, but for some reason, I thought the code would look slightly different...but only in the part where I take the value of 500.
Is there a "better" way of doing this? I'm sure it's obvious, but basically I want to separate the values city and id from the string, "new york (500)".
Appreciate all the help!
Code:
#include <stdio.h>
#include <string.h>
int main()
{
int offset;
char *position;
char *str = "New York (500)";
char *search_str = "(" ;
char city[110];
char id[110]; // this represents the 500 number
int IDSIZE = 3;
position = (char *)strstr(str, search_str);
offset = (int)(position - str);
position = (char *)strncpy(city, str, offset);
printf("String is %s , Offset = %d , City is: %s", str,
offset, city);
str = (str + (offset + 1));
position = (char *)strncpy(id, str, IDSIZE);
printf("Branch id is: %s", id);
return 0;
}