编译接收文件的c++程序的问题
Issues with compiling a C++ program taking in a file
由于某种原因,我在编译时遇到了一些问题,我正在试图找出发生这种情况的确切原因:
g++ Assignment1.cpp test.txt
warning: format not a string literal and no format arguments [-Wformat-security]
printf(op); // To test whether what's scan is what needs to be scanned.
^
/usr/bin/ld:test.txt: file format not recognized; treating as linker script
/usr/bin/ld:test.txt:1: syntax error
collect2: error: ld returned 1 exit status
程序本身:
string op;
char output;
int i,trig[6];
FILE *file_ptr;
file_ptr = fopen(argv[1],"r+");
if (file_ptr != NULL){
fscanf(file_ptr,"%1s (%d,%d) (%d,%d) (%d,%d)", &output, &trig[1], &trig[2],&trig[3],&trig[4],&trig[5],&trig[6]);
char *op = &output;
printf(op); // To test whether what's scan is what needs to be scanned.
}
else {
printf("File Not Found!");
}
fclose(file_ptr);
return 0;
}
和test.txt文件是简单的:T(30,20) (34,30) (12,25)
您也可以这样打开文件我已经删除了字符串op,因为你已经声明了相同名称的char *op
file_ptr=fopen("test.txt","r");
//你的代码现在应该看起来像这样
int main(){
//string op;
char output;
int i,trig[6];
FILE *file_ptr;
file_ptr = fopen("test.txt","r");
if (file_ptr != NULL){
fscanf(file_ptr,"%1s (%d,%d) (%d,%d) (%d,%d)", &output, &trig[1], &trig[2],&trig[3],&trig[4],&trig[5],&trig[6]);
char *op = &output;
printf(op); // To test whether what's scan is what needs to be scanned.
}
else {
printf("File Not Found!");
}
fclose(file_ptr);
return 0;
}
相关文章:
- 警告处理为错误这里有什么问题
- 最小硬币更换问题(自上而下方法)
- 为"adjacent"变量赋值时出现问题
- 我的神经网络不起作用 [XOR 问题]
- 在Ubuntu 16.04上安装Cilk时出现问题
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 编译包含字符串的代码时遇到问题
- Project Euler问题4的错误解决方案
- 问题:什么是QAbstractItemView::NoEditTriggers的反面
- 在编译C++代码(具有dlib和opencv)到WASM时面临问题
- 在进程中对同一管道进行读取和写入时C++管道出现问题
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 一个关于在C++中重载布尔运算符的问题
- 首要问题的答案让值班员搞错了
- setlocale的C++土耳其字符串问题
- 如何重构类层次结构以避免菱形问题
- 基于boost的程序的静态链接——zlib问题
- C++格式化输出问题
- 使用mongocxx驱动程序时包含头文件问题