TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
SUNIL GUTTA
NA
1k
393k
code edit required @C
Nov 11 2013 2:16 AM
Hi
Well i guess its a very basic one reading file and getting index . please check the attachment for requirement doc and output sample .
What i done so far :
CODE :
#
include
<stdio.h>
#
include
<stdlib.h>
#
include
<string.h>
loadArray(fp, names);
int
main()
{
char
names[
60
][
60
];
int
i, n;
FILE * fp;
//set up arrays and variables
loadArray
(fp, names);
// returns with array names[][] loaded from file
findString
(names, fileLen);
// if found print success message on screen else print no success message
}
int
loadArray(FILE * fid,
char
* name[
60
])
{
int
i =
0
; FILE * fp;
char
names[
60
][
60
];
//The 2d
/* opening file for reading */
fp =
fopen
(
"searchlist.txt"
,
"r"
);
if
(fp ==
NULL
)
{
perror
(
"Error opening file"
);
return
(-
1
);
}
while
(
fgets
(names[i],
60
, fp)!=
NULL
)
{
/* writing content to stdout */
printf
(
"
%s
\n
"
, names[i]);
}
fclose
(fp);
return
(
0
);
}
int
findString(
char
* names[
60
], const
char
* name,
int
fileLen)
{
int
n =
strlen
(name);
int
found =
0
;
while
(found < fileLen)
{
if
(names[found]==name)
{
break
;
//is the same as name then break;
}
found++;
}
if
(found < fileLen)
{
return
found;
printf
(
"file length =
%d
"
, found);
// the name was found (hint: found < fileLen)
//then return the found index number
}
else
{
return
-
1
;
// to indicate it was not found
printf
(
"test"
); }
printf
(
"check"
);
}
CHEERS TY FOR SUPPORT
Attachment:
doc.rar
Reply
Answers (
0
)
What is WADL file?
array comparison in C language ?