Questions tagged [fputs]

Anything related to C or C++ standard library functions `fputs` (C) or `std::fputs` (C++). These functions are used to write a null-terminated string to an output stream.

Anything related to C or C++ standard library functions fputs (defined in <stdio.h> C standard header) or std::fputs (defined in <cstdio> C++ standard header). These functions are used to write a null-terminated string to an output stream.

See CPPreference.com:

109 questions
9
votes
3 answers

C++ Make a file of a specific size

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…
OmegaTwig
  • 213
  • 1
  • 4
  • 13
9
votes
1 answer

why fputs and fprintf reverse stream order

I don't get it why fputs and fprintf reverse stream order. int fputs (const char * str, FILE * stream); int fprintf (FILE * stream, const char * format, ...); ssize_t write(int fd, const void *buf, size_t count); I known fprintf put stream in…
qianchenglong
  • 434
  • 5
  • 10
3
votes
1 answer

Why is `printf("%s", "foo")` not being optimized to `fputs("foo", stdout)`?

So both GCC and Clang are smart enough to optimize printf("%s\n", "foo") to puts("foo") (GCC, Clang). That's good and all. But when I run this function through Compiler Explorer: #include void foo(void) { printf("%s",…
mediocrevegetable1
  • 2,614
  • 1
  • 6
  • 25
3
votes
1 answer

^Z character is written to the file or not?

I am writing text to a file using the following program. #include #include int main() { int ch; FILE *fp; fp = fopen("myfile.txt", "w"); if(fp == NULL) { printf("Error opening file\n"); …
Cody
  • 2,010
  • 4
  • 20
  • 52
2
votes
0 answers

PHP : Can file write mode lose data and size?

I have a problem with my logs file, in the past, I used fopen($file, "w+"); with the w+ mode to generate and I wrote on the file, and I used fwrite function to write data and header. With the time I changed the mode to fopen($file, "a"); and I use…
sayou
  • 696
  • 3
  • 21
2
votes
3 answers

w+ not working when trying to read file content

Code: #include void main() { FILE *ptr; char buff[255]; ptr = fopen("Test.txt", "w+"); if (ptr != NULL) { printf("Success\n"); } fputs("Hello", ptr); fgets(buff, 255, (FILE *)ptr); printf("%s",…
Richard
  • 5,945
  • 7
  • 37
2
votes
1 answer

Rewriting some code using fsockopen to use curl instead

My host doesn't allow fsockopen, but it does allow curl. I'm happy using curl from the cli, but haven't had to use it with PHP much. How do I write this using curl instead? $xmlrpcReq and Length are defined earlier. $host =…
Rich Bradshaw
  • 67,265
  • 44
  • 170
  • 236
2
votes
1 answer

Can echo be manipulated to write to a file in PHP

I am writing a code for Sanskrit Natural Language Programming. Earlier the machine was on test mode, so I was testing and editing from an HTML frontend to my PHP code by sending variables via GET method. Now the code has more or less become…
Dhaval Patel
  • 117
  • 1
  • 7
2
votes
2 answers

why when we write \n in the file it converts into \r\n combination?

I read this concept from book that when we attemp to write \n to the file using fputs(), fputs() converts the \n to \r\n combination and then if we read the same line back using fgets () the reverse conversion happens means \r\n back convert to…
Vikas Verma
  • 3,064
  • 6
  • 23
  • 40
2
votes
0 answers

echoing request with fputs

I'm using the code below, to post a request to an API. For debugging purposes: is there a way to echo the full Request (including the Header) that is sent by this code? $data = http_build_query($requests); $url = parse_url($urlfull); …
plocks
  • 561
  • 7
  • 25
2
votes
1 answer

Save php output into variable when using fsockopen

I'm trying to build a php script, which connects to a telnet server and runs a few commands. I would like to save the returned output of a command into a variable. Example: Command: Give me a number! The server returns a number.. lets say it is…
ovabrandon
  • 570
  • 8
  • 16
2
votes
2 answers

how to write the cursor's data in a txt file? visual fox pro

well i have a cursor for example select col1, col2, col3, col4, colN from cursor into into array thecursor my current cursor is the cursor i have got all its data information including null, null information how can i a txt as it: col1, col2, col3,…
angel uc
  • 269
  • 7
  • 21
2
votes
3 answers

Overwrite to a specific line in c

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…
Isaac Gonzalez
  • 1,666
  • 1
  • 16
  • 22
1
vote
1 answer

File writing conflicts : file_get_contents() & fputs()

Im at a bit of a loss, i have 2 scripts 1 which pulls email attachments from a mailbox and a second one which then parses the attachments and adds them to the DB. This works ok most of the time, but is throwing up a few issues every now an again.…
cosmicsafari
  • 3,459
  • 10
  • 34
  • 50
1
vote
5 answers

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

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 main() { FILE *fp; …
tarashish
  • 1,865
  • 20
  • 30
1
2 3 4 5 6 7 8