How can I read this file with space? [duplicate] - c

This question already has answers here:
How do you allow spaces to be entered using scanf?
(11 answers)
Closed 7 years ago.
1 0 Robin Fernandao
2 0 Christiano Gomez
3 1 Lionel Maradona
I have a file that has content like above and I'm trying to read in while loop fscanf(filename,"%d %d %s",array[i],array2[i],array3[i]); Everything ok without player name. It gives me name without last name.How can I fix it? is there any way to read like this file

Try this
fscanf(filename,"%d %d %[^\n]",array[i],array2[i],array3[i]);

Related

How do i read a file from bottom to top and right to left? [duplicate]

This question already has answers here:
Printing lines from a text file in reverse order
(2 answers)
Closed 5 years ago.
Im trying to read a file not just from the last line but from the end of the line to the beginning too. Example:
Im trying
to read a file
How do I want to read:
elif a daer to
gniyrt mI
How do I do that?
You read each line, put all in a buffer ..reverse it and then parse.
The thing is most of the time it is not needed to read the file in reversed manner..But you can try this.
Some nice organized manner of doing this will be..using a LIFO data structure.
You can use a simple array and make it behave like a stack. Push everything then pop from top.

How to change a user password? [duplicate]

This question already has an answer here:
How to add, delete edit username from /etc/passwd [duplicate]
(1 answer)
Closed 6 years ago.
I m playing with /etc/passwd in my C program.
I want to change a user password. are there a standard linux functions that do a such functions ?
Method 1: system("passwd <parameters>");
Method 2: *pwent() function family and also putpwent().
The question is possibly a duplicate.
Linux stores the password in the /etc/shadow file. The second column (delimited by : character) in this file against the user name shows the hashed password.
It's best advised to not touch this file and cause harm. If you must, you can use the vipw utility for editing

How to edit stringd in a batch file [duplicate]

This question already has answers here:
Batch string replace
(3 answers)
Closed 6 years ago.
i'm new to batch programming but i cant find how to manipulate string in a specific manner like we would do in C++.
i want to create a batch file which would change.
00:1E:90:75:9F:9F
to
001E90759F9F
maybe you can try this:
sed 's/00:1E:90:75:9F:9F/001E90759F9F/' your_file_name

command line * linux [duplicate]

This question already has answers here:
Stop shell wildcard character expansion?
(4 answers)
Closed 6 years ago.
i'm trying to write code in C,which implements a simple calculator.
the input should come from the command line, so for example i if i run
./calculator 5 * 2
the result should be 10
the problem is that when i write * it shows all the files in the current directory and the program doesnt behave well.
there is anyway to overcome this problem?
i tried to find here or in other sites solutions,without success.
i need that * will Be interpreted as a char and not as a linux command.
thanks.
In linux shell, the * has special meaning. It is meant for globbing unless it is quoted like below
./calculator 5 '*' 2
You may also escape the asterisk to strip the special meaning from it
./calculator 5 \* 2

How to delete the first line (not overwritten) of a file in C? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Delete a Line from a file in C Language
I know we could overwrite the first line, but here i need to total remove it.
For example, the file contains 100 lines, after i remove the first line, there are 99 lines left and the file size if reduced.
Note that the file is pretty large.
I don't know how to start this, is there any suggestion ? many thanks !
collect all the text of your file into a buffer and copy the same back into yoour file and whenever the required line appears, skip it.. This is all you can do..

Resources