Anda di halaman 1dari 2

1

Familiar with C Language on different operating


systems.(August 2010)
Karen Yineth Gelasio Estupiñán, Operating systems and computing platforms,ESCUELA
COLOMBIANA DE INGENIERÍA

 }
Abstract—Abstract: In this article you will find a small
induction management C compiler in Linux and Windows The first thing we do, is to look for libraries that have the
Operating Systems operations included in the program, then we add brackets in
Index Terms—Compiling ,executing, C Language.
order to obtain expressions syntactically consistent and finally
we use an operation that allows us to keep the program
I. INTRODUCTION running until you press a key, with so that the program does
not end up alone.
T he C language is a very powerful tool, mainly oriented
towards operating systems, this paper will show some
We obtain:
#include <stdio.h>
basic keys to handle files written in this language from Linux #include <stdlib.h>
and Windows. int main(int argc, char *argv[])
Step by step. {
A.Step # 1 Create a file. C and compile it, int i;

The first thing to do is open the Vi text editor and create a for (i = 0; i < argc; i++){
xxx.c Where Xxx is the file name. printf("%s\n",argv[i]);
To compile it, we use the command } getchar();
gcc-c return EXIT_SUCCESS;
and below it the name of the file: }
gcc-c xxx.c
Later, you get a file is a file xxx.o object and invoke it using C. Step #3 What’s this about arguments?
gcc xxx.o
Case Generates a file called In Windows development environment using edit the
previous program. We Configure the development
"a.out"
environment to add the arguments to run.
To generate the executable file and give it a name, you enter
Passing parameters in C is by value, but you can simulate a
the decision:
call by reference using a pointer as an argument.
gcc-o xxx_runnable xxx.c This formal argument having the form:
type_i * arg_i, and when making the call, the actual
B. Step # 2 Correction of the file. parameter has the format: & param.
So, main () is the main function of the program, and
After creating a file in C, now let's try to compile this using parameters can be passed to any other function, as it is only
the instructions as mentioned in the previous step. the first function that is called within a program. Passing
Initially, the file "Lab1.c" was described as follows: parameters can be made from the shell or from the system
#include call which executes a new program using exec.
#include This uses two predefined special arguments: argc and argv.
int main(int argc, char *argv) The parameter argc is an integer that contains the number of
int i; arguments in the command line. It always has a minimum
printf("Numero de argumentos = %d\n",argc); value of 1, as also recorded the program name as a parameter.
for (i = 0; i < argc; i++) Whenever we use the value of a parameter passed to main, to
printf("Argumento %d = %s\n", i, argv[i]); verify the value of argc.
The parameter argv is a vector of pointers to characters.
return EXIT_SUCCESS;
Character pointers point to strings that contain the arguments
that are passed on the command line.
2

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


{
.............
.............
}
In the case of the argument as a null pointer, this function
returns a set of values that are not zero if the command
processor is available, otherwise the function returns a set of
values defined by the application.

D.Step #4 Run it, run it on Windows.


We made a simple program that invokes the word processor
using the "system"

#include <stdio.h>
#include <stdlib.h>
int main()
{
system("notepad");
system("pause");
return EXIT_SUCCESS;
}

This program makes a call to notepad and pauses.


The system function executes a system command or an
external program on disk. This function will be very useful to
stop the program before the end.
run the string passed as a parameter as if we had typed from
the console. The system function is limited to launch a child
shell passing as input the string supplied in the function.
The lower level is to execute an order is to launch the desired
program execution by one of the system calls that start with
exec.
Like the "system" of Windows, the UNIX operating system
provides a system call named 'exec' to launch a program
execution, stored in electronic form. Although there is
basically only one call, the libraries have several functions, all
beginning with 'exec' which differ in the way parameters are
passed to the program to provide ease the programmer.

II. CONCLUSION

By its orientation to the management of operating systems, C


language is quite efficient because using few instructions can
interact directly with the machine and can run on different
operating systems, modifying some statements, allowing us to
say that C Language is almost a universal Language.

Anda mungkin juga menyukai