C Language Tutorials by Ghulam Murtaza Dahar - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

Output

Enter name: Tom Hanks

Name: Tom Hanks

Passing Strings to Functions

String can be passed to function in similar manner as arrays as, string is also an array. Learn more about passing array to a function.

#include <stdio.h>

void Display(char ch[]);

int main(){

char c[50];

printf("Enter string: ");

gets(c);

Display(c); // Passing string c to function.

return 0;

}

void Display(char ch[]){

printf("String Output: ");

puts(ch);

}

Here, string c is passed from main() function to user-defined function Display(). In function declaration, ch[] is the formal argument.

String handling functions

You can perform different type of string operations manually like: finding length of string, concatenating(joining) two strings etc. But, for programmers ease, many library function are defined under header file <string.h> to handle these commonly used talk in C

programming. You will learn more about string hadling function in next chapter.

String Manipulations In C Programming Using Library

Functions

Strings are often needed to be manipulated by programmer according to the need of a problem. All string manipulation can be done manually by the programmer but, this makes programming complex and large. To solve this, the C supports a large number of string handling functions.

There are numerous functions defined in "string.h" header file. Few commonly used string handling functions are discussed below: Function