I have something like this (simplified):
void count(char *fmt)
{
while (*fmt != 'i')
{
fmt++;
}
printf("%c %p\n", *fmt, fmt);
}
int main(void)
{
char *a = "do something";
char *format;
format = a;
printf("%c %p\n", *format, format);
count(format);
printf("%c %p", *format, format);
}
Gives:
d 0x100003f8b
i 0x100003f94
d 0x100003f8b%
Only way to make it work is by doing:
char *count(char *fmt)
{
while (*fmt != 'i')
{
fmt++;
}
printf("%c %p\n", *fmt, fmt);
return (fmt);
}
int main(void)
{
char *a = "do something";
char *format;
format = a;
printf("%c %p\n", *format, format);
format = count(format);
printf("%c %p", *format, format);
}
But I really don't want this since my count function is already returning a value that I need. What can I do to increment format inside the function without returning it?