School of Physics, Mathematics, and Computing 
Not logged in (login)
help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.

Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!" followup message.

How do I ask a good question?
 

Final examination information
Options:
RSS cloud
Jump to:

Alias for default c program

5 of 951 articles shown, currently no other people reading this forum.
photo
From: Sohaib A.
Date: Wed 18th Aug 2021, 1:05pm
Actions: 
Login-to-reply

Hi,

Does anyone know how to set up an alias for a c file containing the default lines of 
code for a c program? (i.e. with standard header files and the main function)?

[Example]

Alias for default c program

photo
From: Christopher M.
Date: Wed 18th Aug 2021, 1:10pm
Actions: 
Login-to-reply

"Sohaib Ahmed" <22*7*9*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Hi,
> 
> Does anyone know how to set up an alias for a c file containing the default lines of 
> code for a c program? (i.e. with standard header files and the main function)?

Shell aliases are usually only one line long;
if we want a multi-line 'alias', we should use a shell function.

This is what I use to quickly create a new C file, and then to edit it with vi.

Just like a shell alias,  you'll need to place it in one of your shell start-up files,
such as in  .bashrc  or  .bash_profile


#
function vc {
if [ ! -r t.c ]
then
cat << END_END > t.c
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

int main(int argc, char *argv[])
{

    return 0;
}
END_END
fi
vim +8 t.c
#

Alias for default c program

photo
From: Amitava D.
Date: Wed 18th Aug 2021, 1:10pm
Actions: 
Login-to-reply

"Sohaib Ahmed" <22*7*9*[email protected]*u*e*t*u*a*e*u*a*> wrote:

> Hi,
> 
> Does anyone know how to set up an alias for a c file containing the default lines of 
> code for a c program? (i.e. with standard header files and the main function)?
> 
> [Example]

create a file where you put all the header files (include statements) and include that file. Including the main() in that file is not advisable, as your code will look strange and chances of mistake are higher.

Alias for default c program

photo
From: Sohaib A.  O.P.
Date: Wed 18th Aug 2021, 2:33pm
Actions: 
Login-to-reply

Thanks so much!

Alias for default c program

photo
From: Sohaib A.  O.P.
Date: Wed 18th Aug 2021, 2:34pm
Actions: 
Login-to-reply

"Amitava Datta" <am*t*v*.*a*t*@*w*.*d*.*u> wrote:

> "Sohaib Ahmed" <22*7*9*[email protected]*u*e*t*u*a*e*u*a*> wrote:
> 
> > Hi,
> > 
> > Does anyone know how to set up an alias for a c file containing the default lines of 
> > code for a c program? (i.e. with standard header files and the main function)?
> > 
> > [Example]
> 
> create a file where you put all the header files (include statements) and include that file. Including the main() in that file is not advisable, as your code will look strange and chances of mistake are higher.

Ok, thanks!
This Page


Program written by: [email protected]
Feedback welcome
Last modified:  4:54pm Oct 24 2021