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.
115
questions
0
votes
3
answers
84
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 ...
-2
votes
1
answer
79
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
36
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
78
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
87
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($...
2
votes
1
answer
1k
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
102
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
44
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
201
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
99
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 ...
0
votes
0
answers
67
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
357
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
421
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
163
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
51
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
47
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
343
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
79
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
276
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
53
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
181
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
820
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
836
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
743
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
799
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
29
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
1k
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
41
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
363
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
44
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
47
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
356
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
271
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
500
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
114
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
165
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
232
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");
...
0
votes
1
answer
19k
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
110
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
195
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 ...
0
votes
1
answer
1k
views
First letter of any word after the first goes missing
I am fairly new to programming and i have done some in school, but they only taught basic functions like printf, scanf, for, while, pointers. I am making a small program that will print user input in ...
1
vote
1
answer
2k
views
When writing to a file, fputs() does not change line
I'm currently trying to create a database in C, using a .txt document as the place to store all the data. But I can't get fputs() to shift line, so everything that my program writes in this .txt ...
1
vote
1
answer
399
views
PHP fputs "waits" until the end of the script
Currently I am trying to develop a PHP script used as a publicly available part of a client/server application. The php script should be used to authenticate users with a one-time token.
The other ...
-4
votes
1
answer
58
views
Cannot read a file and get the outcome
I want to read the file and match 2 words first i connect with a socket get the input write it to a file then i wanna read that file and get the match of 2 words and do something afterword but seems ...
0
votes
1
answer
1k
views
Segmentation Fault on fputs
I am pretty new to C and memory allocation in general. Basically what I am trying to do is copy the contents of an input file of unknown size and reverse it's contents using recursion. I feel that I ...
0
votes
3
answers
95
views
Inserting 400 numbers in a text file
I am trying to write numbers from 1, up to 400 in a text file. I am using the code below, which is running without any errors, but the file is being left empty.
Any help would be appreciated.
#...
0
votes
1
answer
1k
views
php 5.6.7 fwrite vs fputs utf-8 encoding
I have a xml data that is sent as a string in a url.
For example url?data=string
This is sent to another server that I do not have control over and they use fputs so I can not simply change to ...
-1
votes
2
answers
5k
views
writing and reading within a fork - C
The exercise is simple. The father process lets me write my name and surname in a file. The son process waits 5 seconds, then reads and displays it. I can't use the #wait() function.
#include <...