Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: richard7298 on October 25, 2018, 09:17:20 pm

Title: Use of files containing source code
Post by: richard7298 on October 25, 2018, 09:17:20 pm
Hi. I'm a complete newbie to CB and writing code. I'm mostly interested in running code for console applications.

I've copied and pasted into Notepad some simple code I found on the internet.  I've added this file to a Project. When I run debug there is a failure.  But, first of all, should the file containing source code, that I have added to the Project, come under "Others" or should it be saying "Sources"? Thanks. Rich
Title: Re: Use of files containing source code
Post by: BlueHazzard on October 25, 2018, 09:44:52 pm
Quote
But, first of all, should the file containing source code, that I have added to the Project, come under "Others" or should it be saying "Sources"?
What? If you create a project it will create a .c or .cpp file. This files are automatically added to the virtual source folder in codeblocks. Your source files always have to end with .c or .cpp (or other common c++ file endings like .cxx). If the do not end with the right ending codeblocks does not know how to compile them...

Quote
When I run debug there is a failure
Without exact error message no help.... http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_(general)#Q:_How_do_I_report_a_compilation_problem_on_the_forums.3F
Title: Re: Use of files containing source code
Post by: richard7298 on October 25, 2018, 10:03:17 pm
HI. OK, it's as I thought. My .txt file is under "Other" because it's not a source file.

Anyway, I've just got to figure out how I can take code from websites and get it into CB.  I just now created a new (blank) source file in CB.

EDIT: I added the .txt file to the Project. Then I copied and pasted the code from the .txt file into the new source file.  Then I un-added the .txt file. And the code runs OK. Whether this is how one should go about getting code into CB, I know not. But it did work. Rich
Title: Re: Use of files containing source code
Post by: stahta01 on October 26, 2018, 12:52:49 am
http://wiki.codeblocks.org/index.php/Creating_a_new_project (http://wiki.codeblocks.org/index.php/Creating_a_new_project)
Title: Re: Use of files containing source code
Post by: BlueHazzard on October 26, 2018, 03:10:36 am
Quote
EDIT: I added the .txt file to the Project. Then I copied and pasted the code from the .txt file into the new source file.  Then I un-added the .txt file. And the code runs OK. Whether this is how one should go about getting code into CB, I know not. But it did work. Rich
Why not renaming the .txt file to a .c file?
source files are text files with a other ending...
Title: Re: Use of files containing source code
Post by: richard7298 on October 26, 2018, 10:22:35 am
Changing the extension from .txt to .c worked perfectly. Changing the file extension was the first thing I thought about, but because only the name of the file was highlighted when I clicked on "Rename" I thought I could not change the extension. Anyway, I'm now sorted. Thanks. Rich