Programming Articles - Page 1374 of 3366

Write a C program to Reverse a string without using a library function

Bhanu Priya
Updated on 10-Sep-2023 08:20:38

67K+ Views

Using strrev() functionThe function is used for reversing a string.The reversed string will be stored in the same string.Syntaxstrrev (string)Before working on reversing the string without using function, let’s have a look on how to reverse a string using string function strrev(), so that we can easily find the difference and gets clarity on the concept −Example#include main (){    char a[50] ;    clrscr();    printf (“enter a string”);    gets (a);    strrev (a);    printf(“reversed string = %s”, a)    getch (); }Outputenter a string Hello reversed string = olleHWithout using strrev() functionNow let’s see the program ... Read More

Write a C program to convert uppercase to lowercase letters without using string convert function

Bhanu Priya
Updated on 09-Mar-2021 08:57:45

10K+ Views

Before going to know about how to convert upper case to lower case letters without string convert function.Let us have a look on program to convert upper to lower using convert function, then you will get a clarity on what we are doing in the program −Example#include #include int main(){    char string[50];    printf("enter a string to convert to lower case");    gets(string); /reading the string    printf("The string in lower case: %s", strlwr(string)); //strlwr converts all upper    to    lower    return 0; }Outputenter a string to convert to lower case CProgramming LangUage The string ... Read More

Converting string to number and number to string using C language

Bhanu Priya
Updated on 09-Mar-2021 08:55:43

1K+ Views

ProblemWhat do you mean by String to number and number to string conversion in C programming language?SolutionThere are two functions available for conversion. They are −sscanf() − convert string to numbersprintf () − used for converting number to stringString to number conversionWe can convert string to number using the sscanf() function −Syntaxsscanf (string name, “control string”, variable list)Example#include main (){    char a[20] = “02 01 2010”;    int day, mon, yr;    clrscr();    sscanf (a, “%d%d %d”, &day, &mon, &yr);    printf ( “Day =%d”, day);    printf ( “Month = %d”, mon);    printf ( “Year = ... Read More

Explain string library functions with suitable examples in C

Bhanu Priya
Updated on 14-Sep-2023 21:29:01

39K+ Views

String Library functionsThe predefined functions which are designed to handle strings are available in the library string.h. They are −strlen ()strcmp ()strcpy ()strncmp ()strncpy ()strrev ()strcat ()strstr ()strncat ()The strlen () functionIt returns the number of characters in a string.Syntaxint strlen (string name)Example#include main (){    char a[30] = “Hello”;    int l;    l = strlen (a);    printf (“length of the string = %d”, l);    getch (); }Outputlength of the string = 5The strcpy () functionIt is for copying source string into destination string.The length of the destination string >= source string.Syntaxstrcpy (Destination string, Source String);For ... Read More

How to create a pointer for strings using C language?

Bhanu Priya
Updated on 09-Mar-2021 08:47:32

2K+ Views

Arrays of pointers (to strings)Array of pointers is an array whose elements are pointers to the base address of the string.It is declared and initialized as follows −char *a[3 ] = {"one", "two", "three"}; //Here, a[0] is a ptr to the base add of the string "one" //a[1] is a ptr to the base add of the string "two" //a[2] is a ptr to the base add of the string "three"AdvantagesUnlink the two-dimensional array of characters. In (array of strings), in array of pointers to strings there is no fixed memory size for storage.The strings occupy as many bytes as ... Read More

How to assign a pointer to function using C program?

Bhanu Priya
Updated on 09-Mar-2021 08:32:14

755 Views

Pointer to functionIt holds the base address of function definition in memory.Declarationdatatype (*pointername) ();The name of the function itself specifies the base address of the function. So, initialization is done using function name.For example, int (*p) (); p = display; //display () is a function that is defined.Example 1We shall see a program for calling a function using pointer to function −#include main (){    int (*p) (); //declaring pointer to function    clrscr ();    p = display;    *(p) (); //calling pointer to function    getch (); } display (){ //called function present at pointer location    printf(“Hello”); ... Read More

Explain the concept of Array of Pointer and Pointer to Pointer in C programming

Bhanu Priya
Updated on 09-Mar-2021 08:20:19

2K+ Views

Array Of PointersJust like any other data type, we can also declare a pointer array.Declarationdatatype *pointername [size];For example, int *p[5]; //It represents an array of pointers that can hold 5 integer element addressesInitializationThe ‘&’ is used for initializationFor example,int a[3] = {10,20,30}; int *p[3], i; for (i=0; i

Explain the concepts of Pointers and arrays in C language

Bhanu Priya
Updated on 06-Dec-2024 15:26:29

3K+ Views

Pointers and Arrays A pointer in C is a variable that stores the address of another variable, which can be of any type(char, int, function). In a 32-bit system, the size of the pointer is 2 bytes. An array is a collection of similar data items stored in contiguous memory locations. In C, arrays can store various data types(char, int, double float) as well as specific types(pointer structures). For example, if we need to represent an array of 5 elements we need to create it as - int a [5] = {10, 20, 30, 40, 50}; ... Read More

Explain Arithmetic operations using pointers in C language?

Bhanu Priya
Updated on 09-Mar-2021 08:15:19

2K+ Views

Pointer is a variable which stores the address of other variable.Pointer declaration, initialization and accessingConsider the following statement −int qty = 179;Declaring a pointerint *p;‘p’ is a pointer variable that holds the address of another integer variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.int qty = 175; int *p; p= &qty;Arithmetic operations using pointersPointer variables can be used in expressions. For example, if pointer variables are properly declared and initialized then the following statements are valid.a) *p1 + *p2 b) *p1- *p2 c) *p1 * *p2 d) *p1/ *p2 Note: There must be a blank ... Read More

How to pass individual elements in an array as argument to function in C language?

Bhanu Priya
Updated on 09-Mar-2021 08:10:07

2K+ Views

If individual elements are to be passed as arguments, then array elements along with their subscripts must be given in function call.To receive the elements, simple variables are used in function definition.Example 1#include main (){    void display (int, int);    int a[5], i;    clrscr();    printf (“enter 5 elements”);    for (i=0; i

Advertisements