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.
124
questions
-1
votes
1
answer
79
views
fputs causing error corrupted size vs prev size
I am working on a project in C language and my code keeps crashing of fputs command.
This is the code:
void entry_file_creation(int lc, int error_flag_line, char *source_file_name)
{
int j = 0;
...
1
vote
0
answers
32
views
tmpfile_s() reads as empty even after fputs() [duplicate]
Here is a minimal example that does not do what I expected after the counsel of the user in comments to original question. You can see the issue is not about fflush() because it is called after the ...
0
votes
2
answers
90
views
PHP processes a CSV file into 19 Smaller CSV's very slow
I have created this php script which takes a very long time to filter the CSV file into 19 smaller ones. The link for the CSV's is within this google drive line
https://drive.google.com/drive/folders/...
0
votes
0
answers
37
views
I have got struck in a problem where I have the task to update the old line with a new line in a .txt file using C
I have opened the file in "r+" mode and tried to use fputs to replace old_line (line) with new_line (updated_line)
char updated_line[] = "Hello This was ABCD";
fseek(fp, -(strlen(...
1
vote
1
answer
65
views
Why my fputs doesn't work when the file already contains anything?
I try to add a new line to the already existing file, which already consists some text. I found out that when the file contains something, the program stops working after fputs(stringToAdd, myFile); ...
0
votes
3
answers
92
views
How does Visual Studio Code handle the fputs statement for File I/O in "r+" mode?
I have written a code
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *fp;
fp=fopen("lets.txt","r+");
if(fp==NULL)
{
printf("ERROR&...
0
votes
1
answer
52
views
Why when read and write performed back to back in file opened in rb+ mode behaves not as expected in c language
I opened a file in rb+ mode successfuly
Wrote two strings using two fputs.
File ptr moved to 3 byte from file beginning using fseek.
Read four characters successfuly using fgets.
Now when I tried to ...
0
votes
0
answers
48
views
How to copy my file on disk after receive from a socket in C?
I'm programming a server with C and I send file with my client. I receive the file with my server and i want to write it on disk.
I print it to be sure i had it.
Everything are ok but when i write on ...
0
votes
3
answers
551
views
Print char array with fputs or other - C
The first array prints all right.
test[] =
However, when the array is like in the second example, test[][] ={"...","..."};
I get an incompatible warning.
In the second example with ...
-1
votes
1
answer
331
views
Can I use fputs and fgets in file opened in binary
The data in file is random and both alphabet and numbers.
/**** Program to APPEND one file after another file ****/
#include <stdio.h>
#include <fcntl.h>
int main()
{
FILE *fp, *fc;
...
0
votes
1
answer
50
views
Downloading file, changing extension and merging into 1 file
Trying to download files via the URL, rename from the .ADM extension to .txt
then put contents of each file into a single txt file
However its saying the fputs param 2 is a resource
The $logfile['name'...
0
votes
2
answers
212
views
fgets() works wrong in for loop
I am trying to use fgets and fputs to copy-paste a file. I wrote in two ways, one in for loop, the other in while loop. While loop works perfectly, but for loop acts weird.
I tried to debug and wrote ...
1
vote
1
answer
185
views
fputs slowly writing to disk
I have a php script which writes csv files to disk, this is the function:
function fputcsv_content($fp, $array, $delimiter=",", $eol="\n") {
$line = "";
foreach($...
3
votes
1
answer
3k
views
difference between fputs and puts in c
please explain it to me that what is the dfference between
puts(string name) and fputs(string name,stdout)
both of them have the same output especially when I use fgets(string name,n,stdin) for get ...
0
votes
1
answer
208
views
fputs() producing wrong result
My code is producing incorrect result. I don't know why.
When I give the length as 5 and enter the string as "vasanth", this should produce "vasan" as output. But it gives output ...
0
votes
0
answers
48
views
Create a `FILE` from an internal function (not a file)?
POSIX/C defines a number of nice functions to deal with file objects, like fputs and fprintf.
/*
`FILE*` rather than `SomeType*` wanted?
*/
void f(const char *text) {
SomeType* printer_object = \
...
3
votes
1
answer
250
views
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 ...
0
votes
2
answers
162
views
DIfferent behaviour on Edge/Chrome and Firefox on save filename
I work on a project and i am facing a strange behaviour between edge/chrome and firefox. I'm trying to save a file with filename like file_[ip address]-[username].txt.
Sending data from html page ...
1
vote
0
answers
153
views
Smali file is corrupted after writing with fputs()
Goal : i want to inject a one line code in smali
My current approach
I am reading smali file with getline() and writing whole content to a new file with some changes.
Here is code
while(getline(&...
1
vote
1
answer
797
views
Why does C puts appends a newline while fputs doesn't?
The C standard provides two functions, puts and fputs, with puts(s) behaving as fputs(s, stdout) except that it additionally appends a newline:
The puts() function shall write the string pointed to ...
0
votes
3
answers
1k
views
How to read from file and write another in c
I have a input file like this:
This is 1nd Line.
This is 2nd Line.
This 3rd Line.
And I need to output files like
OddLines.txt:
This is 1nd Line.
This 3rd Line.
EvenLines.txt:
This is 2nd Line.
...
1
vote
2
answers
425
views
How to get access of file pointer from one function to another?
I want to store the data in location but whenever I run the code it give me message that the fp is undeclared. I want fp to be working in another function. How to do this?
#include <stdio.h>
#...
0
votes
0
answers
61
views
Write a line to a file line from a struct with a handful of members
typedef struct
{
char name[64];
int balance;
int gain;
}
Player;
"%s\t%d\t%d\n", p.name, p.balance, p.gain ;
I'm trying to input this into my file and I'm wondering if there is any way that I could ...
-1
votes
2
answers
134
views
Confusion about fputs()
#include<stdio.h>
int main()
{
char str[100];
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
fputs("Liverpool", stdout);
fputs("Manchester", stdout);
return 0;
}
...
0
votes
1
answer
559
views
php echo a javascript variable to file.txt
I've this code that works fine to get the user Timezone and echo in php. There's also an alert message before.
<script type="text/javascript"
src="//ajax.googleapis.com/ajax/libs/jquery/2.0.0/...
2
votes
0
answers
136
views
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 ...
1
vote
2
answers
366
views
'Control reaches end of non-void function' in C
I am trying to read the user's input. When I compile the program I get the message, 'control reaches end of non-void function [-Wreturn-type]
}'.
char *read_line(char *buf, size_t sz) {
while(...
0
votes
0
answers
55
views
fputs changes are saved but new changes revert previous ones
I need to read a .txt file, find a string to change it and then save the .txt file again. I want that change to be permanent, meaning if I for example need to change two different things, the first ...
1
vote
1
answer
233
views
Why do we have to dereference stdout here?
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 ...
0
votes
3
answers
1k
views
What is the difference between printf("%s"), printf(s) and fputs?
char s[100]={0};
fgets(s, sizeof(s), stdin);
In the context of the code above, what is the difference between these three?
printf("%s",s);
printf(s);
fputs(s,stdout);
0
votes
1
answer
1k
views
Bad file descriptor after recursive function to open file in C
I want to do a error check in a openFile Function in C and on errno:2 I want to recursivly call again the same function.
I don't get the right answer, if I want to do fputs() after opened the file I ...
0
votes
0
answers
60
views
variable length line in a file deletion in C
I have a file main.txt and I want to delete a line in this file that contains a number passed as an argument to the program.
My code:
FILE *temp = fopen("main.txt","r");
FILE *copy = fopen("temp.txt"...
0
votes
1
answer
958
views
Write ISO 8859-1 string to a file with fputs() in wordpress/PHP
I have a wordpress 4.9.8 website running on PHP 7.0.22. The website uses UTF-8. I need to output the order data in ISO 8859-1 to the FTP server of our fulfillment provider. I have converted the data ...
2
votes
3
answers
1k
views
w+ not working when trying to read file content
Code:
#include <stdio.h>
void main() {
FILE *ptr;
char buff[255];
ptr = fopen("Test.txt", "w+");
if (ptr != NULL) {
printf("Success\n");
}
fputs("Hello", ptr);...
0
votes
1
answer
33
views
How do I combine fputs without throwing error
I'm having trouble on my assignment below. Whenever I try to combine the fputs argument in one line, error will show too much argument in fputs.
What I'm trying to do is to create an output in every ...
0
votes
2
answers
2k
views
Do we need mutex to perform multithreading file IO
I'm trying to do random write (Benchmark test) to a file using multiple threads (pthread). Looks like if I comment out mutex lock the created file size is less than actual as if Some writes are ...
-1
votes
1
answer
94
views
C Programming - type in the program that copies a file using line-at-a-time I/O (fgets and fputs) but use a MAXLINE of 4
I apologize in advance because I just started learning C. This is my code so far.
int main ()
{
char buf [4];
// open the file
FILE *fp = fopen("readme","r");
// Return if could not open file
if (...
0
votes
1
answer
443
views
How to suppress fputs, fsockopen etc warnings without disabling error reporting?
I use fsockopen, fgets and fputs to implement communication protocol with other machine. NetBeans give warning to all '@' before fsockopen, fputs, fgets etc. The solution works but without '@' after ...
0
votes
1
answer
57
views
variation of output Between "fputs" and "printf"
I'm trying to make a program which reads a poem from a text file and displays it.
here is my code..
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *POEM;
POEM = ...
-1
votes
1
answer
53
views
fputs doesn't write before 403 header is triggered
I have a function forbid() that is supposed to write to a log file that access was denied, along with a reason for the denial. For some reason, it's not writing to the logfile.
// function to forbid ...
0
votes
0
answers
428
views
C - fgets and fputs not editing file data
Full code: https://pastebin.com/NpspcJB8
I'm not sure if I'm using fgets() and fputs() correctly, but I need this or something similar in order to edit my file for the program. Within my program, I ...
1
vote
4
answers
333
views
Should I use fputs or putchar?
Here is my following program. I don't want a new line, which is why I used fputs() instead of puts()
char words[5][6] = {"One", "Two", "Three", "Four", "Five"};
for (i = 0; i <= 4; i++)
fputs(...
0
votes
1
answer
619
views
write into file with fputs and a for loop
i want to write into a file like this:
someText
{
"Bob [m]" -> "Fed [m]";
"Tom [m]" -> "Jenny [f]";
...
}
i have:
void file Write()
{
FILE *fp;
fp = fopen("df.dot", "w");
...
3
votes
1
answer
126
views
^Z character is written to the file or not? [duplicate]
I am writing text to a file using the following program.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int ch;
FILE *fp;
fp = fopen("myfile.txt", "w");
if(fp == NULL)
...
-3
votes
4
answers
200
views
Why the input "abc!!!" but the output is not "abc+++"? [closed]
I researching about input/output file.Below code relate some functions such as: fgetc(),fgets(),fputs(). i don't know why it does not work exactly as i want.Thank you so much ! Below is my code:
#...
0
votes
1
answer
262
views
fopen and fputs in c
Hello I am struggling with fopen and fputs when trying to write data to a file.
In particular, the following code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
...
0
votes
0
answers
1k
views
Echo Php Telnet Output / Result
How i can output the result of each comand i send to telnet?
Code I use is:
<?php
$telnet = fsockopen("host", "port", $errno, $errstr, 10);
if($telnet) {
fputs($telnet, "PASSWORD\r\n");
...
2
votes
1
answer
24k
views
fwrite() expects parameter 1 to be resource, string given in c://
I am using latest version of php.. and i stuck on this error
Warning: fwrite() expects parameter 1 to be resource, string given in c:\ this error shows me 6 times
Warning: fclose() expects ...
1
vote
1
answer
145
views
Proper use of fprintf
Is this ever acceptable?
fprintf(fp,"Just a string");
or
fprintf(fp,stringvariable);
versus
fprintf(fp,"%s","Just a string");
It seems confusing to me as the string variable (or constant) is ...
1
vote
1
answer
226
views
File corruption C with fputs and SED
I have a 'queue' (it's not quite FIFO) which is backed by files on the disk once it has run out of its preallocated memory. The built code is being executed on an ARM SBC.
The problem I'm having is ...