ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Book recommendation: The C Programming Language (K&R); it is beautifully elegant, a classic and an icon. My gast is flabbered that no one has mentioned it already
As Sergei points out, the default name of the compiler output 'a.out' can be modified by the '-o' option. When compiling a single source file to it's executable of the same base name, I tend to use the shortcut 'make program'. This will invoke the make command, which would use it's built-in rules to make the specified program. In the case of compiling a C-language source file, make knows how to launch the compiler to compile the C source file, and link the result with the standard libraries to create the runtime executable. This, of course, somewhat violates my earlier admonition about learning the process from the ground up. However, if you add the '-d' option to the make commandline, you will get a view of what make does, allowing you to follow the process and use the same process to build your own applications and, later, to create your own Makefiles. For your cited example, try this:
Code:
make m
./m
To expand on Sergei's point about how to run the resultant executable, the runtime binary that is created will usually end up in the current working directory, '.' . Since the directory '.' is not normally include in $PATH, you must specify the complete path to the executable in order to run it. This isn't a C or programming issue per se, but is a concept foreign to many who are new to Linux shell methods.
As Sergei points out, the default name of the compiler output 'a.out' can be modified by the '-o' option. When compiling a single source file to it's executable of the same base name, I tend to use the shortcut 'make program'. This will invoke the make command, which would use it's built-in rules to make the specified program. In the case of compiling a C-language source file, make knows how to launch the compiler to compile the C source file, and link the result with the standard libraries to create the runtime executable. This, of course, somewhat violates my earlier admonition
Is this the Make command used in compiling sources, I remember once being told to use it to compile basic256 source package, but I chose check install(or some thing like that , which gave out a deb binary). Thanks for the detailed info on the make command compiler.
This is a commercial book. I have no doubt that you will find illegal copies on the net, but asking for copyrighted material here is in direct violation to the LQ rules, please delete this question.
This is a commercial book. I have no doubt that you will find illegal copies on the net, but asking for copyrighted material here is in direct violation to the LQ rules, please delete this question.
I agree, also in my opinion it is an excellent book, but no good choice for a newbie to programming at all. As far as I remember the authors recommend the book for people with programming-experience in other languages.
Is this the Make command used in compiling sources
Yes, almost; it is make, not Make. It is often used to build packages when they are distributed as a source tarball. That is how the authors built them as they were being developed. Now you are the developer, and make is in play for you. make serves two principle roles in the development process.
optimizing the build process
codifying the recipe (Makefile) used to build programs
The former is done using rules known to make regarding dependency relationships between source modules and object modules, and file time/date stamps. Only modified source files need to be compiled to build new object modules. A Makefile provides a way to describe all of the component parts of a package and how they fit together.
make will make a lot more sense to you when you've started creating applications that use multiple source files and libraries.
--- rod.
c m.c
m.c:20:9: warning: missing terminating " character
m.c: In function ‘main’:
m.c:20: error: missing terminating " character
m.c:21:9: warning: missing terminating " character
m.c:21: error: missing terminating " character
m.c:23: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int *’
m.c:23: error: expected ‘)’ before ‘;’ token
m.c:25: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast
/usr/include/stdio.h:339: note: expected ‘const char * __restrict__’ but argument is of type ‘int’
m.c:25: warning: format not a string literal and no format arguments
m.c:25: error: expected ‘)’ before ‘}’ token
m.c:25: warning: passing argument 1 of ‘printf’ makes pointer from integer without a cast
/usr/include/stdio.h:339: note: expected ‘const char * __restrict__’ but argument is of type ‘int’
m.c:25: warning: format not a string literal and no format arguments
m.c:25: error: expected ‘;’ before ‘}’ token
I asked a friend to over look the program and he made the following corrections
Code:
/* BioDATA prograam */
/* Author : Nbl*/
/* Dated 4/7/2011 */
#include<stdio.h>
#include<conio.h> // console input output library function
void main()
{
clrscr(); // clear the output screen
int b;
char p; // declaring variables
printf("Enter your name: ");
scanf("%s",&p);
printf(" \n Your name is %s",&p);
printf(" \n Enter your age: ");
scanf("%d",&b);
printf(" \n Your age is %d",b);
getch(); // hold the output screen
}
Sadly this thing again generated the following message
Quote:
M.c:6:80: error: conio.h: No such file or directory
Now could some-one please identify the mistakes in My program and how should I correct them, also Any advise on How Can i make my friend's version execute.
In the first version of your Biodata program, you forgot some quotatation marks. This would have been obvious if you were using an editor with syntax highlighting (which you should be).
Furthermore, I would recommend never asking your friend anything again. Not only is his knowledge of C++ outdated to the point of worthlessness, but he also lacks the responsibility to confirm that his changes work before declaring himself finished.
In the first version of your Biodata program, you forgot some quotatation marks. This would have been obvious if you were using an editor with syntax highlighting (which you should be).
Furthermore, I would recommend never asking your friend anything again. Not only is his knowledge of C++ outdated to the point of worthlessness, but he also lacks the responsibility to confirm that his changes work before declaring himself finished.
Sir Dugan
I am using gedit editor, Shold I switch to someone else? If so could you please recommend a few.
I am using gedit editor, Shold I switch to someone else? If so could you please recommend a few.
GEdit has syntax highlighting, and it's fine for programming.
But there are two very popular editors that are often used for programming, vi and Emacs. Both of them are not like simple GUI editors, you can't just sit down and use them without learning how they work first. Personally I like Vim (a vi clone with added features), since you can easily do everything with the keyboard without reaching for the mouse. Many others also like Emacs. I think that it's good, but all the key combinations that it uses make my fingers hurt.
You can try different ones until you find what you like.
EDIT: Here's a partial explanation I wrote in another thread:
Quote:
Originally Posted by MTK358
Basically, a plain "char" holds one character (not a string). A "char*" contains a memory address. Why "char" before the asterisk, then? That means that when you "dereference" the pointer (get the value at the memory address it stores), it will be assumed that it's a "char" (You can use "void*" to just refer to a memory address without specifying any type).
So what does this have to do with strings? The idea is that a string is a sequence of "char"s in memory (with a NULL character at the end to indicate the end of the string), one after another, and the "char*" points to the first one. To get a character at the specified index, you add the character's index to the pointer and dereference it:
Code:
second_char = *(str + 1);
(The "*" operator dereferences a pointer)
And this is so common, that there's special syntax for it:
conio.h sounds like something out of the DOS world. For Linux you will need to use the termios API and/or the ncurses library instead. Time to start learning how to link with external libraries. For details, consult your local man pages.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.