Sponsored Content
Top Forums Shell Programming and Scripting Calling a C-function froma shell script Post 302162095 by jisha on Monday 28th of January 2008 02:08:56 AM
Old 01-28-2008
CPU & Memory

Hi ,

I have found a solution for this and it is working !!
Let the two files involved here be sample.c and 1.sh
Open the sample.c
(My program was as below)

# include <stdio.h>
void pline(void);
main(int argc,char *argv[])
{
int i,j;

printf("Wow Entered main\n");

i=strcmp(argv[0],"pline"); /*just to test*/
j=strcmp(argv[1],"pline"); /*just to test*/
printf("i=%d \n j=%d\n",i,j);

if(strcmp(argv[1],"pline") == 0)
{
pline();
printf("done\n");
}
}

void pline(void)
{
int i;
for(i=1;i<5;i++)
printf("Test \n");
printf("\n");
}

Now save the sample.c and execute it so that we get the .exe file
The command for this is :
gcc -o sample.exe sample.c

Now this will give us sample.exe file

Now open the 1.sh

echo " test script to call the c function"
sample.exe pline

save the script and execute it !!!!

Note that either we have to include the patch of sample.exe in the $PATH (environment variable) or give the complete path of sample.exe in the example script as below:


echo " test script to call the c function"
/home/name/script/sample.exe pline

thanks
Js
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

calling a c function from shell

Is it possible to call a C function from within a shell script. This C function is part of an API. What do I need to make it work from my shell script. Anybody please help. (4 Replies)
Discussion started by: seshagiri
4 Replies

2. UNIX for Dummies Questions & Answers

calling one function from another shell script

i have a function defined in one ksh (ksh 1) i want to use that function in another ksh (ksh 2) i am using . $<directoryname>/<ksh name> i am calling the function defined in ksh 1 in ksh 2 i want the returnstatus from the above operation but it is not executing the function what i... (1 Reply)
Discussion started by: trichyselva
1 Replies

3. Shell Programming and Scripting

Calling a C-function froma Perl script

Hi All, How can we call a c function from a perl script? Is it the same way as we do for shell script ? Thanks in advance JS (9 Replies)
Discussion started by: jisha
9 Replies

4. Shell Programming and Scripting

calling a function in Shell script troubleshooting

Some Code After Some code part is executed the control doesnt go to rvin_doxx_scrt.. and the script exits rvin_doxx_scrt() { Some Code } if (som code) ... (4 Replies)
Discussion started by: ultimatix
4 Replies

5. Shell Programming and Scripting

Calling external function in a shell

hi guys, how r u??? please I need you, help me please. I have a shell, in this shell i have this function and another code lines, this function is getting date one day back. the function is in the same shell (FILE 1) Now I need put this function in another file (FILE 2) and calling... (4 Replies)
Discussion started by: acevallo
4 Replies

6. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

7. Homework & Coursework Questions

Shell script calling Perl function, sort and find data, write to new files

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: I must write a shell script that calls two external Perl functions--one of which sorts the data in a file, and... (6 Replies)
Discussion started by: kowit010
6 Replies

8. Shell Programming and Scripting

Is it possible make the shell read functions 1 by 1 and calling an other function?

Greetings, I m wondering if it's possible do do the following : I have a simple function called "FindMoveDelete" which does the following : FindMoveDelete() { find . -iname "$FILENAME*.ext" -exec mv {} "$PATH/$VAR" \; && find . -maxdepth 1 -type d -iname "$FILENAME*" -exec rm -rf {}... (6 Replies)
Discussion started by: Sekullos
6 Replies

9. Shell Programming and Scripting

Calling a function in cpp file inside shell script

Hi I need to call a function written in a cpp file with arguments inside the shell script..Can anyone help me how to do this:( (1 Reply)
Discussion started by: rkrish
1 Replies

10. Shell Programming and Scripting

Calling Pl/sql function in shell script to modify csv

I need to 1.Open a csv 2.Process the csv i.e. Modify 2 column in the csv. To modify the column the value needs to be passed to a pl/sql function and the return value should be updated For eg: If column 2 E,then E will be passed in database function which will return Employee. 3. Write a... (5 Replies)
Discussion started by: Chinky23
5 Replies
QSORT(3)                                                     Linux Programmer's Manual                                                    QSORT(3)

NAME
qsort, qsort_r - sort an array SYNOPSIS
#include <stdlib.h> void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): qsort_r(): _GNU_SOURCE DESCRIPTION
The qsort() function sorts an array with nmemb elements of size size. The base argument points to the start of the array. The contents of the array are sorted in ascending order according to a comparison function pointed to by compar, which is called with two arguments that point to the objects being compared. The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respec- tively less than, equal to, or greater than the second. If two members compare as equal, their order in the sorted array is undefined. The qsort_r() function is identical to qsort() except that the comparison function compar takes a third argument. A pointer is passed to the comparison function via arg. In this way, the comparison function does not need to use global variables to pass through arbitrary arguments, and is therefore reentrant and safe to use in threads. RETURN VALUE
The qsort() and qsort_r() functions return no value. VERSIONS
qsort_r() was added to glibc in version 2.8. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +-------------------+---------------+---------+ |Interface | Attribute | Value | +-------------------+---------------+---------+ |qsort(), qsort_r() | Thread safety | MT-Safe | +-------------------+---------------+---------+ CONFORMING TO
qsort(): POSIX.1-2001, POSIX.1-2008, C89, C99, SVr4, 4.3BSD. NOTES
To compare C strings, the comparison function can call strcmp(3), as shown in the example below. EXAMPLE
For one example of use, see the example under bsearch(3). Another example is the following program, which sorts the strings given in its command-line arguments: #include <stdio.h> #include <stdlib.h> #include <string.h> static int cmpstringp(const void *p1, const void *p2) { /* The actual arguments to this function are "pointers to pointers to char", but strcmp(3) arguments are "pointers to char", hence the following cast plus dereference */ return strcmp(* (char * const *) p1, * (char * const *) p2); } int main(int argc, char *argv[]) { int j; if (argc < 2) { fprintf(stderr, "Usage: %s <string>... ", argv[0]); exit(EXIT_FAILURE); } qsort(&argv[1], argc - 1, sizeof(char *), cmpstringp); for (j = 1; j < argc; j++) puts(argv[j]); exit(EXIT_SUCCESS); } SEE ALSO
sort(1), alphasort(3), strcmp(3), versionsort(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at https://www.kernel.org/doc/man-pages/. 2017-09-15 QSORT(3)
All times are GMT -4. The time now is 12:44 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy