![]() |
Finding out word occurence without c library calls
Hi,
I got benifited a lot from this forum.Can you please have a look at my requirement and assist me in the same. stripos — Find position of first occurrence of a case-insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls. Thanks in Advance sri. |
Re: Finding out word occurence without c library calls
This is just idea make it efficient when you are goin to write coode
1. Take two pointer ptr1 and ptr2 pointing to haystack and needle respectively. 2. if contain of ptr1 is equal to contained of ptr2 then ++ptr1 and ++ptr2 3. if ptr2 points to NULL and ptr1 also points to space then print " you got that string" return 4. if ptr2 points to NULL and ptr1 not points to space then goto step 5 5. if contained of ptr1 is not equal to contained of ptr2 then increment ptr1 untill space come and go to for next string reset ptr2 (ptr2 should point to again needle 6. if contained of ptr1 is not equal to contained of ptr2 and ptr1==NULL return -1 |
Re: Finding out word occurence without c library calls
Hi myinboxid,
did you manage to write the code? if so can you share it with us. it would help alot! thanks! |
Re: Finding out word occurence without c library calls
Try this......
Code:
#include <stdio.h> |
Re: Finding out word occurence without c library calls
thanks a lot mr.anandc..:D
|
Re: Finding out word occurence without c library calls
Please use code block when you have code snippets in posts
|
Re: Finding out word occurence without c library calls
Hello,
Please explain to me about this question. I seriously do not understand what this question is asking for. the question is as below: Write the following function in C. stripos — Find position of first occurrence of a case-insensitive string int stripos ( char* haystack, char* needle, int offset ) Returns the numeric position of the first occurrence of needle in the haystack string. Note that the needle may be a string of one or more characters. If needle is not found, stripos() will return -1. The function should not make use of any C library function calls. The code should be developed entirely by you and not extracted from other's work. |
Re: Finding out word occurence without c library calls
It's fairly easy, except I do not know what "offset" is for; the question does not specify this. What it means is that it finds the existence of one string (let's say "lo reb") inside another (let's say "Hello Rebecca"), without considering case. So stripos("Hello Rebecca","lo reb",0) would return 3, and stripos("Hello Rabbit, hello Rebecca","lo reb",0) would return 18. This differs from the standard C library function strstr in that strstr is case sensitive (also iirc strstr returns a char* not an int). So one solution would be to find the source code for strstr() and replace "if (str1[i]==str2[j])" with "if (toupper(str1[i])==toupper(str2[j]))", although that would technically constitute "extracted from other's work"...
|
Re: Finding out word occurence without c library calls
i too got the same question for my technica test...
kindly pls let me know the answer for this question.. plz post the code |
Re: Finding out word occurence without c library calls
The idea is that *you* are supposed to write the code. The test is testing your programming skills, not mine.
Post what you've got so far and explain in detail where you're stuck, and we'll try to unstick you, but we won't do your homework for you. |
| All times are GMT +5.5. The time now is 02:49. |