• C

getting values from input.txt

input.txt;

-1 0 -1 2 3
1 -1 3 -1 4
...
...

i try to get values from txt. i got pozitive integers but i cant get -1. if it is -1 , i am going to do something.

this sample input.txt file can be change, not unique.

thanks.
LVL 1
thefirstfbliAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
ozoConnect With a Mentor Commented:
for( i=0;i<=4; i++ ){
  fscanf(INPUTFILE,"%d",&array[i]);
}
for( i=0;i<=4; i++ ){
  printf("array[%d] = %d, ",i,array[i]);
}
0
 
ozoCommented:
how are you getting them?
are you using scanf with a %d format?
0
 
thefirstfbliAuthor Commented:
yes, i try fgets too.

i cant do it because of it is not unique txt. it may different.
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
ozoCommented:
why is being different a problem?
what kinds of differences can there be?
0
 
thefirstfbliAuthor Commented:
i try to say; different txt inputs, -1 can be anywhere in txt.

like

0 1 2 3 -1
3 11 -1 3
1 -1 2 4
.. .. .. ect
0
 
thefirstfbliAuthor Commented:
but there wont be a -2, -3 ...ect

 only negative number that will be there is -1. i need all pozitives too.
0
 
ozoCommented:
why is that a problem?
0
 
thefirstfbliAuthor Commented:
the problem is;

first of all i want to see the integers with printf for ex;

for second txt;

array[0]=1, array[1]=2, array[3]=3, array[4]=-1
array2[0]=3, array[1]=11, .... ect.

i want to print them first of all, i try to do more complex thing with these numbers.
0
 
thefirstfbliAuthor Commented:
ow.. it takes negative sign.. i did not understand but yes works.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.