Questions tagged [cstdio]

A C++ wrapper for C standard IO header stdio.h.

55 questions
1
vote
3 answers

How to use gets() in cpp

These days I am learning strings and arrays in cpp. In my school they taught us to take a string as user input, one have to use gets() but it isn't working on any of the compilers I have. I have already tried using cstdio library, still errors. I…
meispi
  • 63
  • 2
  • 6
1
vote
1 answer

Creating a custom iterator struct to work with cstdio

I'm trying to create a iterator to go through my file. My file is binary and have int values inside, so in my point of view, it should work like that. But I'm getting errors says "invalid use of data-member 'IntFile::file' "So i marked in code…
1
vote
0 answers

Eclipse CDT Debug Has Extra Lines In Scanf

I have a simple piece of code that will echo whatever you type into the console: int main(){ setvbuf(stdout, NULL, _IONBF, 0); char c = -1; while(scanf("%c", &c) == 1){ printf("%c", c); } } But when I Debug this code in…
Moddl
  • 360
  • 3
  • 13
1
vote
1 answer

Locate the source of a bug with sscanf

I've been struggling with this for too long. Let's say i have this minimal code: test.cxx #include #include int main (int argc, char *argv[]) { const char *text = "1.01 foo"; float value = 0; char other[8]; int code…
t-bltg
  • 854
  • 9
  • 17
1
vote
3 answers

Difference between %u and %d in scanf()

In C++, if I read an integer from a string, it seems it does not really matter whether I use u or d as conversion specifier as both accept even negative integers. #include using namespace std; int main() { int u, d; sscanf("-2",…
Palec
  • 12,743
  • 8
  • 69
  • 138
1
vote
1 answer

C++: fopen() returns handle to empty file

I'm getting a strange file handle from fopen; the pointer itself isn't NULL, but the file it represents has no size, and feof(file) is already set... what could be causing this? (I triple checked the file itself, it exists, has data, and the file's…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
1
vote
2 answers

How to avoid losing data when overwriting a file is interrupted in C

I've written code that saves progress in my game, but one of my biggest fears is the brief window of time during saving when that data might become corrupted should the computer crash or lose power. Is there standard methodology using only C's…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
1
vote
2 answers

Rotating two dimensional array of integers

I have a problem with a task for my IT school. The problem is : Turn the frame of an array to left. Input : First get the numbers of tests (t). Then for each test get l and k (line and column), 3 <= l, k <= 100. Then fill the matrix with numbers…
Setzo
  • 39
  • 1
  • 7
1
vote
1 answer

cstdio fopen and fclose not working correctly on osx

I'm using tinyxml through openframeworks which uses cstdio for file access. I can see the example program quite happily create and write files but there is no delete so my plan is to implement remove, but after trying to run this code in my own…
cool mr croc
  • 725
  • 1
  • 13
  • 33
1
vote
1 answer

Inplace edit of a file using cstdio?

I have a file that I'm writing data to, using the functions in cstdio. I want to make sure the file has successfully been written to file without any interruptions, so I know what to expect from the file when I later read from it. The way I aim to…
Anne Quinn
  • 12,609
  • 8
  • 54
  • 101
0
votes
0 answers

How to set UTF-8 encoding without BOM for CStdioFileEx?

I try to read a file via MFC: CString string; CStdioFileEx gameFile; bool have_file = false; if (PathFileExists(filePathsAndNames[i].first + L"\\main.lua")) { gameFile.Open(filePathsAndNames[i].first + L"\\main.lua", CFile::modeRead); …
0
votes
0 answers

why wont the computer recognize gets()

#include #include using namespace std; int main() { char str[100]; cout << "Enter a string: "; gets(str); cout << "You entered: " << str; return 0; } This is code sample has been coppied exactly form…
0
votes
0 answers

std::cin unexpected behaviour on large integer input

cin unexpected behaviour on large integer input When a large integer is provided as input, std::cin causes unexpected behaviour in the program. std::cin unexpected behaviour when there is an integer overflow #include int main() { int…
0
votes
0 answers

C- nonblocking read of all stdin

I am seeking some non-blocking function (will return any available input but will not wait for more input from the user) which will read any and all stdin data up to n into a buffer and return how many bytes were read. int n_bytes = readn(&buff,…
0
votes
0 answers

Small issue with my coding in C using stdio.h

I am currently working on a code and I keep having issues with my code. I will add it below, but for some reason, whenever I ask for the input, it skips over the second scanner and goes straight to the third. Does anyone know what the issue may…