User forums > General (but related to Code::Blocks)

How to debug when the inputs getted from a text file?

(1/2) > >>

wanggaoteng:
Hi, when I solving the questions in my textbook, a problems appears. I want to debug using codeblocks, but the inputs which the program needs are quoted from a text file. For example, the nameof my project is "test", and the main program is:

--- Code: ---#include "stdio.h"
int main(void)
{
    int ch;
    while((ch=getchar())!=EOF)
    {
        putchar(ch);
    }
    printf("\n");
    return 0;
}

--- End code ---
Before running this program, I create a text file which named as "test.txt" in the same folder with .exe file(test.exe). Then I open the terminal, and typing "test.exe <test.txt", and the results appears.
I want to debug this program using codeblocks, is there any way to make the inputs getted from the test.txt file when debuging?

Best Regards.

BlueHazzard:
You have to put the text file in the folder where the project file is.
If you run your application in codeblocks the base path is not the path of the executable, but of the project file...

wanggaoteng:

--- Quote from: BlueHazzard on May 27, 2019, 12:59:58 pm ---You have to put the text file in the folder where the project file is.
If you run your application in codeblocks the base path is not the path of the executable, but of the project file...

--- End quote ---

Hi, BlueHazzard,
I can't understand the messages above, it's abstract. Can you give me a detailed instruction?
Thank you.

BlueHazzard:
Your ptoject structure on your harddisk should be something like this:

--- Code: ---exampleProject
|-- exampleProject.cbp
|-- bin
      |-- Debug
             |--- exampleProject.exe
             |--- test.txt


--- End code ---
but if you debug you have to put your test.txt in the root folder of the project, so that it looks like this:

--- Code: ---exampleProject
|-- exampleProject.cbp
|-- test.txt
|-- bin
      |-- Debug
             |--- exampleProject.exe

--- End code ---

wanggaoteng:

--- Quote from: BlueHazzard on May 28, 2019, 04:01:08 pm ---Your ptoject structure on your harddisk should be something like this:

--- Code: ---exampleProject
|-- exampleProject.cbp
|-- bin
      |-- Debug
             |--- exampleProject.exe
             |--- test.txt


--- End code ---
but if you debug you have to put your test.txt in the root folder of the project, so that it looks like this:

--- Code: ---exampleProject
|-- exampleProject.cbp
|-- test.txt
|-- bin
      |-- Debug
             |--- exampleProject.exe

--- End code ---

--- End quote ---
Hi, BlueHazzard,
Thanks for presenting the detailed message. I followed your instruction, but when the little yellow arrow reaches "while((ch=getchar())!=EOF)" in debug, then the arrow disappears, and I must input some message in the console. It is not my propose, I want to let the inputs (while((ch=getchar())!=EOF)) got from the text file (test.txt) when debugging. Is there anyway to do that?

Navigation

[0] Message Index

[#] Next page

Go to full version