These codes have no problem and do well, but, I want to use "gets(buf);" instead of "cin.getline(buf, sizeof(buf));". However, when substituting "cin.getline(buf, sizeof(buf));" for "gets(buf);" or "fgets(buf, sizeof(buf), stdin);", a problem occurs in "popentest.cpp".
What is the problem in popentest.cpp? and, How can I solve?
p.s. In test.cpp, I must use gets().
// test.cpp
// make for Test
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char *trim(char *str){
char *blanks = (char *)" \n\t\v\r";
size_t lIdx = strspn(str, blanks);
Quote, do not use it. Why?
Try something like this:
1 2
char LittleBuffer[2];
gets(LittleBuffer);
and input a long string (longer than 2 chars). It will fail (Buffer too short assertion, probably).
Because when you get the string, your program does not know how many chars LittleBuffer can store. On MS Visual Studio you can use gets_s and input its size too, but:
1. It requires the .NET Framework installed
2. It's MSVS-only, as of now, as far as i know.