•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 456,589 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,591 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 501 | Replies: 3
![]() |
•
•
Join Date: Oct 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 0
I spent 5-6 hours today to try to get a working searchfunction for my textfile,
can someone please put me in the right direction?
I have this textfile, its a register over contacts:
For example, i want to search for "yahoo" and find the sally string.
I cant put a code since i have noone working or close to it.
However, my contacts is in the memory like this:
contact[0]=James Brown:555-12345:james@brown.com
contact[1]=Jack Yellow:555-42345:jack@yellow.com
..and so on.
The closest solution ive tried is "memchr" to compare contact strings with a searchstring,
but cant get it to work, tried to understand it but i dont. Im new to programming.
Maybe its a bad sollution anyway..
can someone please put me in the right direction?
I have this textfile, its a register over contacts:
Number Contacts = 3* James Brown:555-12345:james@brown.com Jack Yellow:555-42345:jack@yellow.com Sally White:555-12345:sally@yahoo.com
For example, i want to search for "yahoo" and find the sally string.
I cant put a code since i have noone working or close to it.
However, my contacts is in the memory like this:
contact[0]=James Brown:555-12345:james@brown.com
contact[1]=Jack Yellow:555-42345:jack@yellow.com
..and so on.
The closest solution ive tried is "memchr" to compare contact strings with a searchstring,
but cant get it to work, tried to understand it but i dont. Im new to programming.
Maybe its a bad sollution anyway..
Last edited by Fredszky : Nov 4th, 2007 at 1:57 pm.
•
•
Join Date: Oct 2007
Location: Cherry Hill, NJ
Posts: 1,878
Reputation:
Rep Power: 13
Solved Threads: 193
The strstr() function
Hope this helps.
#include <string.h> will return whether or not a given string contains a given substring. C Syntax (Toggle Plain Text)
char string_to_search[] = "Hello, world!"; char string_to_find[] = "world"; char *pos; pos = strstr( string_to_search, string_to_find ); if (pos != NULL) printf( "found it at index %d\n", (int)(pos -string_to_search) ); else printf( "not found\n" );
Hope this helps.
Last edited by Duoas : Nov 4th, 2007 at 3:33 pm.
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
adsense adult advertising biometrics blogging bomb book business coding community copyright development earth engine environment failure forum google internet legal malware marketing mcafee microsoft monetization msn news operating pagerank phishing photo privacy publishing revenue search security seo silverlight software space spyware support system technical universe video web webmaster wiki yahoo
- can't open folders w/o search function popping up (Windows NT / 2000 / XP / 2003)
- pagination and search (PHP)
- I have a problem in building class Tree (Binary Search) (Python)
- Phonebook program! (C)
- i can't seem to make my search function work.... help!... (C)
- Windows Search Not Functioning (Windows NT / 2000 / XP / 2003)
- SEARCH function on Windows Explorer does not work (Windows NT / 2000 / XP / 2003)
- Internet Explorer won't load, cannot open search (Viruses, Spyware and other Nasties)
Other Threads in the C Forum
- Previous Thread: file handeling
- Next Thread: How to save a file to C://+string



Linear Mode