15,908,906 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 14009930 (Top 10 by date)
Member 14009930
6-Oct-18 14:07pm
View
that's the whole code i'm running man and this is my file
o Lenan
McCormuck Dun
Dun
o Linaghe
McMorris
Bane
McMortagh
Keaton
Keaton
Keaton
Keaton
o ffeagh
Hefernon
Cosby
Mase
Mase
Stafford
Sutton
Sutton
Alcock
Protector
Stafford
Stafford
Clandalke
Cheevers
mc Cody
Debbon
Vynes
Vicars
ffenen
Browne
McKillpatricke
McMurrogh
Vinecomb
Wicken
starrford
Synnott
Synnot
Synnot
wicken
Waller
Wicken
Cheeuers
mc Murtagh
mc Cody
mc Donell
waller
Wagstaffe
Wagstaffe
Dunne
mc Larenc
just input any random value out of this for str and run the program you will get frequency values but it shows wrong value when i input something like "mc Larenc" which has space in between
Member 14009930
6-Oct-18 12:49pm
View
but using strcmp is returning all the values that are in the list
Member 14009930
6-Oct-18 12:09pm
View
Deleted
can you please improve my code and post it actually i tried strcmp but it wasn't working
Member 14009930
6-Oct-18 11:57am
View
Deleted
thats the input we are taking from user example let str =mc Cody now i need to check how many times this occurs in my file
Member 14009930
6-Oct-18 11:54am
View
Deleted
i need to compare whole string but my code is just comparing first 2 chars like you said
Member 14009930
6-Oct-18 11:53am
View
Deleted
data written in file is given above. this code is running but just not giving the right number of occurrences of a string
Member 14009930
6-Oct-18 11:52am
View
Deleted
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include <ctype.h>
int Search_in_File(char *fname, char *str) {
FILE *my_file;
int sr_num = 1;
int result = 0;
char temp1[512];
int l;
my_file=fopen ("names.csv","r");
if (my_file==NULL){
perror (" empty file ");
return -1;}
while(fgets(temp1, 512, my_file) != NULL) {
if((strstr(temp1, str)) != 0) {
l++;
printf(" match found on line: %d\n", sr_num);
printf("\n%s \n", temp1);
result++;
}
sr_num++;
}
printf(" frequency of occuring is %d ",l);
if(result == 0) {
printf("\n match not found\n");
}
if(my_file) {
fclose(my_file);
}
return(0);
}
int hash1(char *a){
int hash=0;
while (*a){
hash = hash + *a;
a++;
}
return hash;
}
int main(){
FILE * myfile;
char a[256];
char j[50];
char b[5381];
int i,k, result;
myfile=fopen ("names.csv","r");
if (myfile==NULL){
perror (" empty file ");}
else
{
while ( fgets ( a, sizeof a, myfile ) != NULL ){
int i = hash1(a);
if (b[i] != *a)k=1;
if (b[i] == *a){
k++;
while (b[i] !=' '){
i=i+1;
}
}
b[i]= *a;
printf(" %d %d %s " ,i,k,a);
printf("\n");
}
}
printf("enter the name you want to search \n");
scanf("%s",j);
result = Search_in_File("name.csv", j);
if(result == -1)
perror("Error");
return 0;
}
Member 14009930
6-Oct-18 11:50am
View
Deleted
mc Murtagh
mc Cody
mc Donell
waller
Wagstaffe
Wagstaffe
Dunne
mc Larenc
these are the values in the file now suppose i want to find how many times name mc Larenc occurs in the file i run the above code with these values in temp and it gives me answer 5 that is strstr function writeen above is not comparing two strings its just comparing first two characters and giving answer 5 so it want replacement of the function strstr
Member 14009930
6-Oct-18 11:44am
View
Deleted
@richard temp1 are string values that are being read from a file and str is input string from user whose no of occurrences we need to check in the file
Member 14009930
6-Oct-18 11:41am
View
Deleted
i have written whole code @Cpallini i'm just having problem in comparing the two strings so i posted only this much code.
Show More