调试传递了两个参数的 C 程序
Debugging C program with two arguments passed
我已经修复了代码中的一些语法错误,现在程序可以正常编译了。但是当我执行程序时,outputFile 是空的。 outputFile 应该以相反的顺序包含 inputFile 的内容。我正在尝试调试 CodeLite
IDE.
中的代码
我需要调试传递了两个参数(inputFile 和 outputFile)的代码。我似乎没有在 CodeLite
IDE 中找到该选项。我该怎么做?
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUFFER_SIZE 256
int main (int argc, char *argv[]){
FILE *inputFile, *outputFile;
int fileSize;
int pointer;
char buffer[BUFFER_SIZE];
/* Check for correct user's inputs. */
if( argc !=3 ) {
fprintf(stderr, "USAGE: %s inputFile outputFile.\n", argv[0]);
exit(-1);
}
/* Make sure input file exists. */
if( (inputFile = fopen(argv[1], O_RDONLY))) {
fprintf(stderr, "Input file doesn't exist.\n");
exit(-1);
}
/* Create output file, if it doesn't exist. Empty the file, if it exists. */
if((outputFile = fopen(argv[2], "a+"))) {
fclose(inputFile);
exit(-1);
}
/* Find the size of the input file. */
fileSize = fseek(inputFile, 0, SEEK_END);
/* Read input file and write to output file in reversed order.*/
for(pointer=fileSize-1; pointer>=0; pointer--) {
/*Write content in the buffer to the output file */
while(!feof(inputFile))
{
fgets(buffer, BUFFER_SIZE, inputFile); //reads 256 bytes at a time
fputs (buffer , outputFile );
}
}
fclose(inputFile);
fclose(outputFile);
return(0);
}
http://codelite.org/LiteEditor/ProjectSettings:
项目设置 >> 常规 >> 命令参数
- 右键单击项目文件夹
- Select 项目设置
- 常规 -> 执行 -> 程序参数
我已经修复了代码中的一些语法错误,现在程序可以正常编译了。但是当我执行程序时,outputFile 是空的。 outputFile 应该以相反的顺序包含 inputFile 的内容。我正在尝试调试 CodeLite
IDE.
我需要调试传递了两个参数(inputFile 和 outputFile)的代码。我似乎没有在 CodeLite
IDE 中找到该选项。我该怎么做?
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define BUFFER_SIZE 256
int main (int argc, char *argv[]){
FILE *inputFile, *outputFile;
int fileSize;
int pointer;
char buffer[BUFFER_SIZE];
/* Check for correct user's inputs. */
if( argc !=3 ) {
fprintf(stderr, "USAGE: %s inputFile outputFile.\n", argv[0]);
exit(-1);
}
/* Make sure input file exists. */
if( (inputFile = fopen(argv[1], O_RDONLY))) {
fprintf(stderr, "Input file doesn't exist.\n");
exit(-1);
}
/* Create output file, if it doesn't exist. Empty the file, if it exists. */
if((outputFile = fopen(argv[2], "a+"))) {
fclose(inputFile);
exit(-1);
}
/* Find the size of the input file. */
fileSize = fseek(inputFile, 0, SEEK_END);
/* Read input file and write to output file in reversed order.*/
for(pointer=fileSize-1; pointer>=0; pointer--) {
/*Write content in the buffer to the output file */
while(!feof(inputFile))
{
fgets(buffer, BUFFER_SIZE, inputFile); //reads 256 bytes at a time
fputs (buffer , outputFile );
}
}
fclose(inputFile);
fclose(outputFile);
return(0);
}
http://codelite.org/LiteEditor/ProjectSettings:
项目设置 >> 常规 >> 命令参数
- 右键单击项目文件夹
- Select 项目设置
- 常规 -> 执行 -> 程序参数