Make file 
Author Message
 Make file

I have these 2 simple C programs, would you tell me please how can I
write Make File to compile these both files on UNIX. What should be the
name of Make file and what shoul the commands i have to use.
Thanks a lot

Regards.. Nameir

-----------------   1st program------------------

main()
{
int a, b,ans;
printf("Type two intergers:");
scanf("%d%d", &a, &b);
ans=formula(a,b);
printf("The sum of the squares is %d", ans);

Quote:
}

--------------------- 2nd program -------------------
main()
{
formula(int x,int y)
{
return (x*x + y*y);
Quote:
}



Fri, 07 Jan 2000 03:00:00 GMT  
 Make file


Quote:
>I have these 2 simple C programs, would you tell me please how can I
>write Make File to compile these both files on UNIX. What should be the
>name of Make file and what shoul the commands i have to use.
>Thanks a lot

For simple one-translation unit programs, it's hardly worthwhile to create
a makefile. Just compile the thing with

    cc program_name.c -o executable_name

If the <math.h> functionality is used, you also have to add `-lm' at
the end of the command line.

Quote:
>Regards.. Nameir

>-----------------   1st program------------------

>main()
>{
>int a, b,ans;
>printf("Type two intergers:");
>scanf("%d%d", &a, &b);

You must #include <stdio.h> to use scanf() or otherwise provide a valid
declaration for it: variable argument functions can't be used without
a prior prototype.

Quote:
>ans=formula(a,b);

Your program doesn't contain the definition of the formula() function,
and it's not a standard library function either. This means that your
program probably won't build.

Quote:
>printf("The sum of the squares is %d", ans);

It would be useful to print a newline character here, as in:

    printf("The sum ... is %d\n", ans);

Also, provide a successful exit status from main() with

    return 0;

Quote:
>}

>--------------------- 2nd program -------------------
>main()
>{
>formula(int x,int y)
>{
>return (x*x + y*y);
>}

This is a syntax error. You cannot define functions within functions in C.
And even if you could, your braces are not balanced.

Why don't you purchase a C tutorial textbook and possibly a reference manual so
that you can learn C properly?  I suggest the second edition of _The C
Programming Language_ by Brian Kernighan and Dennis Ritchie, which has plenty
of tutorial material and is aimed at people with programming experience. As a
reference manual,  I would recommend the latest edition of Harbison and Steele.



Fri, 07 Jan 2000 03:00:00 GMT  
 Make file

It looks like you're trying to reference a function (formula) from the
1st program (let's call it 1st_program.c from now on) in the 2nd program
(let's call it 2nd_program.c from now on).  What you need to do is
modify 1st_program.c like this:

#include <stdio.h> /*so printf and scanf will work*/
#include "formula.h" /*so the program can find formula*/

main()
/*main really returns an int and has some args, but don't worry
 *about it.
 */
{
int a, b, ans ;
printf("Type two integers:"); /*spell integers correctly*/
scanf("%d%d", &a, &b);
ans=formula(a,b);
printf("The sum of the squares is %d", ans);

/*you could have combined the formula and printf calls like so:
 *printf( "The sum of the squares is %d", formula(a,b) );
 */

Quote:
}

2nd_program.c has some real problems.  The first is that it doesn't need
to have a main function, just the formula function.  You need to include
the return type for formula since you don't have a prototype for it:

int formula(int x,int y)
/*if you included a function prototype, all
 *you would need here would be formula( x, y )
 */
{
return (x*x +y*y);

Quote:
}

Since you only have two files to compile, you really don't need to
bother with a make file.  If you have GNU C compiler (which you probably
do since you have UNIX), the command to compile the program is

$ gcc -o myprogram 1st_program.c 2nd_program.c

Thanks for at least making an effort at doing the job yourself before
posting to the newsgroup.  Usually people just want their homework
done.  It appears to me that you gave a try (although maybe not the
hardest try ;->).

Jay



Fri, 07 Jan 2000 03:00:00 GMT  
 Make file


scribbled :

Quote:
>I have these 2 simple C programs, would you tell me please how can I
>write Make File to compile these both files on UNIX. What should be the
>name of Make file and what shoul the commands i have to use.
>Thanks a lot

>Regards.. Nameir

You don't need a makefile.
Just type the name of the compiler (gcc, cc, hpcc) and then the name of
the C file, and see what happens.

Then, chmod 700 file, and type ./file to run it.
--
Revised anti-spam in use : remove X to reply -
'Xnetbook' becomes 'netbook'

Anti-spam thermonuclear warheads cheap at only $300!



Sun, 09 Jan 2000 03:00:00 GMT  
 Make file


Quote:
>I have these 2 simple C programs, would you tell me please how can I
>write Make File to compile these both files on UNIX.

Sure, but I guarantee you'd get better quality answers on
comp.unix.programmer; in comp.lang.c, you can expect to get poor answers
and/or flames, because you're too damn rude to figure out where you
should have asked the question.  (Hint:  Your question has *NOTHING* at all to
do with C; if it did,
        1.  It would not apply to fortran, Basic, Pascal, or Lisp.
        2.  It would apply just as well to Macintosh, PC, and Amiga users.
        )

Quote:
>What should be the
>name of Make file and what shoul the commands i have to use.

Fine.

Quote:
>-----------------   1st program------------------
>main()
>{
>int a, b,ans;
>printf("Type two intergers:");
>scanf("%d%d", &a, &b);
>ans=formula(a,b);
>printf("The sum of the squares is %d", ans);
>}
>--------------------- 2nd program -------------------
>main()
>{
>formula(int x,int y)
>{
>return (x*x + y*y);
>}

Okay.  Create a file called "omigod.i'm.too.dumb.to.use.a.manual".
In it, put the following lines:
        1stprogram.exe:
                cc -o 1stprogram.exe "   1st program"

        2ndprogram.exe:
                cc -o 2ndprogram.exe " 2nd program "

Now type "make -n -f omigod.i'm.too.dumb.to.use.a.manual".  make will
print out a list of commands; drag over these commands with the left mouse
button, then press the middle mouse button.  If you haven't got a three button
mouse, go cry at a user support services person.

By the way, neither of those is even close to a C program; the first refers
to a function that is never defined, the second tries to begin a function
definition inside main(), which is not allowed, and never finishes main.

If you had asked this in the right place, I would have given useful advice.
As is, this is really more intended as a bit of stress relief for all of the
other people who came here hoping to find something about *C* to read.

-s
--
Copyright 1997 Peter Seebach - seebs at solon.com - C/Unix Wizard

The *other* C FAQ, the hacker FAQ, et al.  http://www.solon.com/~seebs
Unsolicited email (junk mail and ads) is unwelcome, and will be billed for.



Sun, 09 Jan 2000 03:00:00 GMT  
 Make file

Someone asked how to write a make file for a badly presented program
and...

Quote:

> Okay.  Create a file called "omigod.i'm.too.dumb.to.use.a.manual".
> In it, put the following lines:
>         1stprogram.exe:
>                 cc -o 1stprogram.exe "   1st program"

>         2ndprogram.exe:
>                 cc -o 2ndprogram.exe " 2nd program "

> Now type "make -n -f omigod.i'm.too.dumb.to.use.a.manual".

Out of all the bad and inappropriate questions posted here recently, why
pick on this poor guy?  It's your only post in a while, Seebs; there
must be better prey.
--
Regards... Ian.

Ian R. Hay - Toronto, Canada

http://www3.sympatico.ca/ian.hay/
----------------------------------------------------------------------



Sun, 09 Jan 2000 03:00:00 GMT  
 Make file

Quote:


> scribbled :
> >I have these 2 simple C programs, would you tell me please how can I
> >write Make File to compile these both files on UNIX. What should be the
> >name of Make file and what shoul the commands i have to use.
> >Thanks a lot

> >Regards.. Nameir

> You don't need a makefile.
> Just type the name of the compiler (gcc, cc, hpcc) and then the name of
> the C file, and see what happens.

He will see several error messages (maybe mixed with some warnings).

Quote:
> Then, chmod 700 file, and type ./file to run it.

No chance, because there is not output file to change or run.

BTW, makefiles are not features of standard C. They are programming
tools, mostly distruibuted with some compilers. For help on creating
makefiles for a Unix compiler, it's best to ask the Unix programming
experts in:

Stephan
(initiator of the campaign against grumpiness in c.l.c)

Quote:
> --
> Revised anti-spam in use : remove X to reply -
> 'Xnetbook' becomes 'netbook'

> Anti-spam thermonuclear warheads cheap at only $300!



Mon, 10 Jan 2000 03:00:00 GMT  
 Make file

Quote:

>Whatever happened to self-reliance?

I thought USENET had made that obsolete long ago.

--

``Not only is UNIX dead, it's starting to smell really bad.'' -- rob



Tue, 11 Jan 2000 03:00:00 GMT  
 Make file

Quote:

> Someone asked how to write a make file for a badly presented program
> and...


> > Okay.  Create a file called "omigod.i'm.too.dumb.to.use.a.manual".
> > In it, put the following lines:
> >         1stprogram.exe:
> >                 cc -o 1stprogram.exe "   1st program"

> >         2ndprogram.exe:
> >                 cc -o 2ndprogram.exe " 2nd program "

> > Now type "make -n -f omigod.i'm.too.dumb.to.use.a.manual".

> Out of all the bad and inappropriate questions posted here recently, why
> pick on this poor guy?  It's your only post in a while, Seebs; there
> must be better prey.

No, I agree with Peter. It was a very stupid question deserving the
answer he gave. It was as funny and stress relieving as he intended it
to be and I would just whish for more stuff like that. It did contain a
certain grumpiness, but thats Peters speciality and it was presented in
a way that I could not object to.

It's a sad fact that there are only a few capable of writing such fine
examples of sarcastic humour and they do not have the time to comment
all the stupid questions in c.l.c

Stephan
(initiator of the campaign against grumpiness in c.l.c)



Tue, 11 Jan 2000 03:00:00 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Making files "Installable"

2. Home made file save dialog box

3. Home made file save dialog box

4. Shortcut code makes file but it doesn't work ?

5. Making a static LIB files instead of DLL files

6. Making a new function or simulating the making

7. Exe made by MSVC5.0 and Dlls made by 6.0 causes problem

8. Exe made by MSVC5.0 and Dlls made by 6.0 causes problem

9. MAKING an EXE file in Vc++ .Net

10. making a File readonly

11. Making .dll file through C programming

12. making a header file...

 

 
Powered by phpBB® Forum Software