Q:

C program to pass an array of strings to a function

0

C program to pass an array of strings to a function

Given an array of strings and we have to pass to a user define function and print the strings in the function using C program.

Here is the function that we have used in the program,

void Strfun(char **ptr , int count)

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to pass an array of strings to a function in C

/*  
C program to array of strings to a function
*/

#include <stdio.h>

// function to print strings
void Strfun(char **ptr , int count)
{
    int i=0;
    
    for(i=0;i<count;i++)
    {
        printf("\nString [%d] : %s",i,ptr[i]);  fflush(stdout);
    }
    
}

// main function
int main()
{ 
   // Declare an array of pointers and assign some strings into it
   char *buff[4] = {"Hello function" , "How are you?" , "Catch some strings"};
	
   // Passing array of strings to Function
   Strfun(buff,3); // here 3 is the number of strings
   return 0;
}

Output

String [0] : Hello function
String [1] : How are you?
String [2] : Catch some strings

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C program to pass multiple type of arguments to a ... >>
<< C program to pass a string to a function...