want each word in file to list in array Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to read words from a text file and add to an array of strings?How do I check whether a file exists without exceptions?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?How do I include a JavaScript file in another JavaScript file?Loop through an array in JavaScriptHow to read a file line-by-line into a list?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
After Sam didn't return home in the end, were he and Al still friends?
Delete free apps from library
Printing attributes of selection in ArcPy?
Is it dangerous to install hacking tools on my private linux machine?
Positioning dot before text in math mode
Putting class ranking in CV, but against dept guidelines
Simple Http Server
Why do early math courses focus on the cross sections of a cone and not on other 3D objects?
How do living politicians protect their readily obtainable signatures from misuse?
What is a more techy Technical Writer job title that isn't cutesy or confusing?
What does Turing mean by this statement?
Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?
Tips to organize LaTeX presentations for a semester
What are the main differences between Stargate SG-1 cuts?
Found this skink in my tomato plant bucket. Is he trapped? Or could he leave if he wanted?
How much damage would a cupful of neutron star matter do to the Earth?
The test team as an enemy of development? And how can this be avoided?
How to change the tick of the color bar legend to black
Can an iPhone 7 be made to function as a NFC Tag?
What does it mean that physics no longer uses mechanical models to describe phenomena?
What would you call this weird metallic apparatus that allows you to lift people?
What is the difference between CTSS and ITS?
As a dual citizen, my US passport will expire one day after traveling to the US. Will this work?
What does 丫 mean? 丫是什么意思?
want each word in file to list in array
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to read words from a text file and add to an array of strings?How do I check whether a file exists without exceptions?Create ArrayList from arrayHow do I check if an array includes an object in JavaScript?How to append something to an array?How do I include a JavaScript file in another JavaScript file?Loop through an array in JavaScriptHow to read a file line-by-line into a list?How to check if an object is an array?How do I remove a particular element from an array in JavaScript?For-each over an array in JavaScript?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
im a bit stuck here and not sure how to approach this. I have a list of words in a .txt file
example:
apple
orange
peach
pear
berry
i would like my c program to be able to read the file, and put each word into a array address so i can access each word and analyze it when needed.
for example:
apple -> array[0]
orange -> array[1]
peach -> array[2]
pear -> array[3]
berry -> array[4]
All help is appreciated.
Here is what i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAX, fpointer);
printf("%s", fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
return 0;
The warnings i receive are:
filetest.c: In function ‘main’:
filetest.c:22:13: warning: format ‘%s’ expects argument of type ‘char *’,
but
argument 2 has type ‘FILE * aka struct __sFILE64 *’ [-Wformat=]
printf("%s", fpointer);
~^
filetest.c:23:11: warning: passing argument 1 of ‘strcpy’ makes pointer from
integer without a cast [-Wint-conversion]
strcpy(list[i], singleline);
^~~~
In file included from filetest.c:3:0:
/usr/include/string.h:38:8: note: expected ‘char * restrict’ but argument is
of
type ‘char’
char *strcpy (char *__restrict, const char *__restrict);
c arrays file
|
show 2 more comments
im a bit stuck here and not sure how to approach this. I have a list of words in a .txt file
example:
apple
orange
peach
pear
berry
i would like my c program to be able to read the file, and put each word into a array address so i can access each word and analyze it when needed.
for example:
apple -> array[0]
orange -> array[1]
peach -> array[2]
pear -> array[3]
berry -> array[4]
All help is appreciated.
Here is what i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAX, fpointer);
printf("%s", fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
return 0;
The warnings i receive are:
filetest.c: In function ‘main’:
filetest.c:22:13: warning: format ‘%s’ expects argument of type ‘char *’,
but
argument 2 has type ‘FILE * aka struct __sFILE64 *’ [-Wformat=]
printf("%s", fpointer);
~^
filetest.c:23:11: warning: passing argument 1 of ‘strcpy’ makes pointer from
integer without a cast [-Wint-conversion]
strcpy(list[i], singleline);
^~~~
In file included from filetest.c:3:0:
/usr/include/string.h:38:8: note: expected ‘char * restrict’ but argument is
of
type ‘char’
char *strcpy (char *__restrict, const char *__restrict);
c arrays file
1
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
1
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.char list[150] = fgets(fpointer, 150, );
is total nonsense.
– Barmar
Mar 8 at 23:30
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49
|
show 2 more comments
im a bit stuck here and not sure how to approach this. I have a list of words in a .txt file
example:
apple
orange
peach
pear
berry
i would like my c program to be able to read the file, and put each word into a array address so i can access each word and analyze it when needed.
for example:
apple -> array[0]
orange -> array[1]
peach -> array[2]
pear -> array[3]
berry -> array[4]
All help is appreciated.
Here is what i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAX, fpointer);
printf("%s", fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
return 0;
The warnings i receive are:
filetest.c: In function ‘main’:
filetest.c:22:13: warning: format ‘%s’ expects argument of type ‘char *’,
but
argument 2 has type ‘FILE * aka struct __sFILE64 *’ [-Wformat=]
printf("%s", fpointer);
~^
filetest.c:23:11: warning: passing argument 1 of ‘strcpy’ makes pointer from
integer without a cast [-Wint-conversion]
strcpy(list[i], singleline);
^~~~
In file included from filetest.c:3:0:
/usr/include/string.h:38:8: note: expected ‘char * restrict’ but argument is
of
type ‘char’
char *strcpy (char *__restrict, const char *__restrict);
c arrays file
im a bit stuck here and not sure how to approach this. I have a list of words in a .txt file
example:
apple
orange
peach
pear
berry
i would like my c program to be able to read the file, and put each word into a array address so i can access each word and analyze it when needed.
for example:
apple -> array[0]
orange -> array[1]
peach -> array[2]
pear -> array[3]
berry -> array[4]
All help is appreciated.
Here is what i have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAX, fpointer);
printf("%s", fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
return 0;
The warnings i receive are:
filetest.c: In function ‘main’:
filetest.c:22:13: warning: format ‘%s’ expects argument of type ‘char *’,
but
argument 2 has type ‘FILE * aka struct __sFILE64 *’ [-Wformat=]
printf("%s", fpointer);
~^
filetest.c:23:11: warning: passing argument 1 of ‘strcpy’ makes pointer from
integer without a cast [-Wint-conversion]
strcpy(list[i], singleline);
^~~~
In file included from filetest.c:3:0:
/usr/include/string.h:38:8: note: expected ‘char * restrict’ but argument is
of
type ‘char’
char *strcpy (char *__restrict, const char *__restrict);
c arrays file
c arrays file
edited Mar 9 at 0:18
Michael Bacha
asked Mar 8 at 23:05
Michael BachaMichael Bacha
32
32
1
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
1
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.char list[150] = fgets(fpointer, 150, );
is total nonsense.
– Barmar
Mar 8 at 23:30
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49
|
show 2 more comments
1
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
1
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.char list[150] = fgets(fpointer, 150, );
is total nonsense.
– Barmar
Mar 8 at 23:30
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49
1
1
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
1
1
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.
char list[150] = fgets(fpointer, 150, );
is total nonsense.– Barmar
Mar 8 at 23:30
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.
char list[150] = fgets(fpointer, 150, );
is total nonsense.– Barmar
Mar 8 at 23:30
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49
|
show 2 more comments
2 Answers
2
active
oldest
votes
A quick lesson on reading compiler errors and warnings may help you write code that compiles.
filetest.c: In function ‘main’:
filetest.c:10:25: warning: passing argument 1 of ‘fgets’ from incompatible
pointer type [-Wincompatible-pointer-types]
char list[150] = fgets(fpointer);
^~~~~~~~
In file included from filetest.c:1:0:
/usr/include/stdio.h:213:9: note: expected ‘char * restrict’ but argument is
of
type ‘FILE * aka struct __sFILE64 *’
char * fgets (char *__restrict, int, FILE *__restrict);
filetest.c:10:25
is the file, line and column where the error/warning is. Any decent editor should let you jump right there. But the compiler helpfully highlights it for you.
char list[150] = fgets(fpointer);
^~~~~~~~
What's wrong? The compiler tells you that too: note: expected ‘char * restrict’ but argument is of type ‘FILE*‘ ...
, and helpfully shows you the correct prototype for the function: char * fgets (char *__restrict, int, FILE *__restrict);
.
So you have passed a FILE*
where the compiler wanted a char*
. And you've only passed one argument where the function expects 2. (
Which is what the next error also says).
You've edited the question to fix the error I pointed out, but you just need to keep doing the same thing:format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘FILE *
means you passed a FILE*
where the function wants a char*
.
passing argument 1 of ‘strcpy’ makes pointer from integer
means you passed an integer where the function wants a pointer. And so on...
add a comment |
I ended up getting it. Works how i need it, thank you everyone for the tips.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define MAXCHAR 20
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX][MAXCHAR];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAXCHAR , fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
for(i=0;i<MAX;i++)
if ( strcmp ( list[i] , "STOP" ) == 0 )
break;
printf("%s", list[i]);
return 0;
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072226%2fwant-each-word-in-file-to-list-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
A quick lesson on reading compiler errors and warnings may help you write code that compiles.
filetest.c: In function ‘main’:
filetest.c:10:25: warning: passing argument 1 of ‘fgets’ from incompatible
pointer type [-Wincompatible-pointer-types]
char list[150] = fgets(fpointer);
^~~~~~~~
In file included from filetest.c:1:0:
/usr/include/stdio.h:213:9: note: expected ‘char * restrict’ but argument is
of
type ‘FILE * aka struct __sFILE64 *’
char * fgets (char *__restrict, int, FILE *__restrict);
filetest.c:10:25
is the file, line and column where the error/warning is. Any decent editor should let you jump right there. But the compiler helpfully highlights it for you.
char list[150] = fgets(fpointer);
^~~~~~~~
What's wrong? The compiler tells you that too: note: expected ‘char * restrict’ but argument is of type ‘FILE*‘ ...
, and helpfully shows you the correct prototype for the function: char * fgets (char *__restrict, int, FILE *__restrict);
.
So you have passed a FILE*
where the compiler wanted a char*
. And you've only passed one argument where the function expects 2. (
Which is what the next error also says).
You've edited the question to fix the error I pointed out, but you just need to keep doing the same thing:format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘FILE *
means you passed a FILE*
where the function wants a char*
.
passing argument 1 of ‘strcpy’ makes pointer from integer
means you passed an integer where the function wants a pointer. And so on...
add a comment |
A quick lesson on reading compiler errors and warnings may help you write code that compiles.
filetest.c: In function ‘main’:
filetest.c:10:25: warning: passing argument 1 of ‘fgets’ from incompatible
pointer type [-Wincompatible-pointer-types]
char list[150] = fgets(fpointer);
^~~~~~~~
In file included from filetest.c:1:0:
/usr/include/stdio.h:213:9: note: expected ‘char * restrict’ but argument is
of
type ‘FILE * aka struct __sFILE64 *’
char * fgets (char *__restrict, int, FILE *__restrict);
filetest.c:10:25
is the file, line and column where the error/warning is. Any decent editor should let you jump right there. But the compiler helpfully highlights it for you.
char list[150] = fgets(fpointer);
^~~~~~~~
What's wrong? The compiler tells you that too: note: expected ‘char * restrict’ but argument is of type ‘FILE*‘ ...
, and helpfully shows you the correct prototype for the function: char * fgets (char *__restrict, int, FILE *__restrict);
.
So you have passed a FILE*
where the compiler wanted a char*
. And you've only passed one argument where the function expects 2. (
Which is what the next error also says).
You've edited the question to fix the error I pointed out, but you just need to keep doing the same thing:format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘FILE *
means you passed a FILE*
where the function wants a char*
.
passing argument 1 of ‘strcpy’ makes pointer from integer
means you passed an integer where the function wants a pointer. And so on...
add a comment |
A quick lesson on reading compiler errors and warnings may help you write code that compiles.
filetest.c: In function ‘main’:
filetest.c:10:25: warning: passing argument 1 of ‘fgets’ from incompatible
pointer type [-Wincompatible-pointer-types]
char list[150] = fgets(fpointer);
^~~~~~~~
In file included from filetest.c:1:0:
/usr/include/stdio.h:213:9: note: expected ‘char * restrict’ but argument is
of
type ‘FILE * aka struct __sFILE64 *’
char * fgets (char *__restrict, int, FILE *__restrict);
filetest.c:10:25
is the file, line and column where the error/warning is. Any decent editor should let you jump right there. But the compiler helpfully highlights it for you.
char list[150] = fgets(fpointer);
^~~~~~~~
What's wrong? The compiler tells you that too: note: expected ‘char * restrict’ but argument is of type ‘FILE*‘ ...
, and helpfully shows you the correct prototype for the function: char * fgets (char *__restrict, int, FILE *__restrict);
.
So you have passed a FILE*
where the compiler wanted a char*
. And you've only passed one argument where the function expects 2. (
Which is what the next error also says).
You've edited the question to fix the error I pointed out, but you just need to keep doing the same thing:format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘FILE *
means you passed a FILE*
where the function wants a char*
.
passing argument 1 of ‘strcpy’ makes pointer from integer
means you passed an integer where the function wants a pointer. And so on...
A quick lesson on reading compiler errors and warnings may help you write code that compiles.
filetest.c: In function ‘main’:
filetest.c:10:25: warning: passing argument 1 of ‘fgets’ from incompatible
pointer type [-Wincompatible-pointer-types]
char list[150] = fgets(fpointer);
^~~~~~~~
In file included from filetest.c:1:0:
/usr/include/stdio.h:213:9: note: expected ‘char * restrict’ but argument is
of
type ‘FILE * aka struct __sFILE64 *’
char * fgets (char *__restrict, int, FILE *__restrict);
filetest.c:10:25
is the file, line and column where the error/warning is. Any decent editor should let you jump right there. But the compiler helpfully highlights it for you.
char list[150] = fgets(fpointer);
^~~~~~~~
What's wrong? The compiler tells you that too: note: expected ‘char * restrict’ but argument is of type ‘FILE*‘ ...
, and helpfully shows you the correct prototype for the function: char * fgets (char *__restrict, int, FILE *__restrict);
.
So you have passed a FILE*
where the compiler wanted a char*
. And you've only passed one argument where the function expects 2. (
Which is what the next error also says).
You've edited the question to fix the error I pointed out, but you just need to keep doing the same thing:format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘FILE *
means you passed a FILE*
where the function wants a char*
.
passing argument 1 of ‘strcpy’ makes pointer from integer
means you passed an integer where the function wants a pointer. And so on...
answered Mar 9 at 0:25
AShellyAShelly
26.4k1173129
26.4k1173129
add a comment |
add a comment |
I ended up getting it. Works how i need it, thank you everyone for the tips.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define MAXCHAR 20
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX][MAXCHAR];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAXCHAR , fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
for(i=0;i<MAX;i++)
if ( strcmp ( list[i] , "STOP" ) == 0 )
break;
printf("%s", list[i]);
return 0;
add a comment |
I ended up getting it. Works how i need it, thank you everyone for the tips.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define MAXCHAR 20
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX][MAXCHAR];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAXCHAR , fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
for(i=0;i<MAX;i++)
if ( strcmp ( list[i] , "STOP" ) == 0 )
break;
printf("%s", list[i]);
return 0;
add a comment |
I ended up getting it. Works how i need it, thank you everyone for the tips.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define MAXCHAR 20
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX][MAXCHAR];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAXCHAR , fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
for(i=0;i<MAX;i++)
if ( strcmp ( list[i] , "STOP" ) == 0 )
break;
printf("%s", list[i]);
return 0;
I ended up getting it. Works how i need it, thank you everyone for the tips.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 150
#define MAXCHAR 20
int main()
FILE * fpointer;
fpointer = fopen("input.txt", "r");
char singleline[MAX];
char list[MAX][MAXCHAR];
int i;
while ( !feof(fpointer))
printf("File readn");
for ( i = 0 ; i < MAX ; i++ )
fgets(singleline, MAXCHAR , fpointer);
strcpy(list[i], singleline);
fclose(fpointer);
for(i=0;i<MAX;i++)
if ( strcmp ( list[i] , "STOP" ) == 0 )
break;
printf("%s", list[i]);
return 0;
answered Mar 9 at 3:27
Michael BachaMichael Bacha
32
32
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55072226%2fwant-each-word-in-file-to-list-in-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
stackoverflow.com/questions/34149140/…
– Antti Haapala
Mar 8 at 23:10
1
And what happens if you try to build and run that code? What is your question?
– Yunnosch
Mar 8 at 23:17
sorry i should of posted the warnings. Here they are
– Michael Bacha
Mar 8 at 23:24
You need to read a good C textbook/tutorial, to learn how to work with files and arrays.
char list[150] = fgets(fpointer, 150, );
is total nonsense.– Barmar
Mar 8 at 23:30
well this is exactly why i am asking, i am a first year student and just started learning about these functions this past week
– Michael Bacha
Mar 8 at 23:49