- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I have fx3s board, I want to find the length of a string between two special characters ( '$' and '#') in my program,
will u please help me how to find this ?
regards,
Ajith.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ajith,
I assume that the string is stored in a char array and '$' comes first while traversing array from left to right.
Here is the simple C code:
void main()
{
char string[50];
int i, length = 0;
printf("Enter a string \n");
gets(string);
for(i=0; string[i] != '$'; i++);
/* keep going through each character of the string till '#' encounters*/
for (++i; string[i] != '#'; i++)
{
length++;
}
printf("The length of a string between the special characters is %d \n", length);
}
Thanks & Regards
Abhinav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Ajith,
I assume that the string is stored in a char array and '$' comes first while traversing array from left to right.
Here is the simple C code:
void main()
{
char string[50];
int i, length = 0;
printf("Enter a string \n");
gets(string);
for(i=0; string[i] != '$'; i++);
/* keep going through each character of the string till '#' encounters*/
for (++i; string[i] != '#'; i++)
{
length++;
}
printf("The length of a string between the special characters is %d \n", length);
}
Thanks & Regards
Abhinav
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thank you Abhinav.