fputs

c : gets() and fputs() are dangerous functions?

烂漫一生 提交于 2019-12-04 21:26:12
In the computer lab at school we wrote a program using fputs and the compiler returned an error gets is a dangerous function to use and a similar error for fputs but at home when i type in this bit of code: #include <stdio.h> main() { FILE *fp; char name[20]; fp = fopen("name.txt","w"); gets(name); fputs(name,fp); fclose(fp); } i get no errors what so ever. The one at school was similar to this one, just a bit lengthy and having more variables. I use codeblocks at home and the default gcc provided with fedora at school. Could it be a problem with the compiler? With gets you need exactly know

Why do we have to dereference stdout here?

烂漫一生 提交于 2019-12-04 05:31:29
问题 I am trying to call fputs(str, stdout); from assembly. Why should I push dword [stdout] instead of just push stdout ? Since in C we don't do fputs(str, *stdout) , why do we need to dereference stdout in assembly? Full code: extern fputs extern stdout section .data hw: db "Hello World!", 10, 0 section .text global main main: enter 0,0 push dword [stdout] ;push stdout push hw call fputs leave mov eax, 0 ret 回答1: You're dereferencing the asm label stdout , which is equivalent to &stdout in C. It

Overwrite to a specific line in c

别来无恙 提交于 2019-12-03 21:56:51
问题 I have a file of about 2000 lines of text that i generate in my program, every line has the information of an employee and it's outputed like this 1 1 Isaac Fonseca 58 c 1600 1310.40 6 1 0.22 2164.80 1 2 1 Manuel Gutierrez 22 d 1700 1523.37 4 1 0.13 897.26 1 3 1 Daniel Bernal 34 c 1600 1195.84 2 1 0.26 836.16 1 4 1 Miguel Gonzalez 43 e 1800 1195.84 0 1 0.15 0.00 1 But i whenever i edit an employee information i have to update the file, what i'm doing it's i search for the line and try to

fputs/puts dangerous (in C)?

假如想象 提交于 2019-12-02 08:50:19
I've been having trouble with fputs lately: when printing some strings in a text file with fputs, it happens I get other characters than A-Z, a-z, 0-9 in (chars that aren't part of the string). I made absolutely sure the strings all end with the null character. Unfortunately I can't give you more information, since I did not personally test the program, that was the feedback I received. But after I replaced fputs with fprintf it worked properly. So my question is: is fputs sort of dangerous? Have you ever had trouble with it? fputs is not inherently dangerous. Of course without example code

C++ Make a file of a specific size

青春壹個敷衍的年華 提交于 2019-11-30 14:06:38
Here is my current problem: I am trying to create a file of x MB in C++. The user will enter in the file name then enter in a number between 5 and 10 for the size of the file they want created. Later on in this project i'm gonna do other things with it but I'm stuck on the first step of creating the darn thing. My problem code (so far): char empty[1024]; for(int i = 0; i < 1024; i++) { empty[i] = 0; } fileSystem = fopen(argv[1], "w+"); for(int i = 0; i < 1024*fileSize; i++){ int temp = fputs(empty, fileSystem); if(temp > -1){ //Sucess! } else{ cout<<"error"<<endl; } } Now if i'm doing my math