Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

C notes for all students

Rating
-
Sold
-
Pages
19
Uploaded on
05-06-2025
Written in
2024/2025

Looking for easy-to-understand C Programming notes that help you score better in exams and understand core concepts faster? These notes are student-friendly, made with clarity, simplicity, and exactly what you need for university exams and assignments. What’s Included: • Complete coverage of C basics to advanced • Well-structured notes for each unit/module • Key programs with example outputs • Short notes for revision and viva • Clean formatting for easy reading • Includes frequently asked questions

Show more Read less
Institution
Course

Content preview

S2-GXEST 204-PROGRAMMING IN C (2024 Scheme)

Module 2 - Part 2 - Syllabus

• Strings
• Declaring a string variable
• Reading and displaying strings
• String related library functions
• Programs for string matching.


Strings
• A String in C programming is a sequence of characters terminated with a null
character ‘\0’.
• The C String is stored as an array of characters.
• There is an extra terminating character which is the Null character (‘\0’) used to
indicate the termination of a string that differs strings from normal character
arrays.




C String Declaration
• Declaring a string in C is as simple as declaring a one-dimensional array of
character type.

char string_name[size];

eg: char str[50];

• Like in array, we can skip the size in declaration.

char string_name[];

eg: char str[];

• 2D array of strings declaration.

S2-GXEST 204-PROGRAMMING IN C (2024 Scheme) Reenu Renjith - Assistant Professor CSE - MBITS 1

, char string_name [] [];

eg: char str[5][50];
//creates an array of 5 strings, with each string that has a capacity of
50 characters.


C String Initialization

• Assigning a String Literal without Size
char str[] = "GeeksforGeeks";

• Assigning a String Literal with a Predefined Size
char str[50] = "GeeksforGeeks";

• Assigning Character by Character with Size
char str[14] = { 'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};

• Assigning Character by Character without Size
char str[] = { 'G','e','e','k','s','f','o','r','G','e','e','k','s','\0'};

• Array of strings initialization
char str_arr[4][50] = {“mango”, “banana”, “apple”, “pear”);

// C program to illustrate strings

#include <stdio.h>
#include <string.h>

int main()
{
// declare and initialize string
char str[] = "Geeks";

// print string
printf("%s\n", str);

int length = 0;
length = strlen(str);

// displaying the length of string
printf("Length of string str is %d", length);

return 0;
}



S2-GXEST 204-PROGRAMMING IN C (2024 Scheme) Reenu Renjith - Assistant Professor CSE - MBITS 2

, Output

Geeks
Length of string str is 5


Reading and displaying strings
• Reading strings :
o Using scanf()
o Here, the string is read only till the whitespace is encountered.
o Using fgets()

o The fgets() function reads content from the file up to the next line
break and writes it into a char array.
o It stops reading when either (num-1) characters have been read, a
newline is encountered, or the end-of-file is reached, and it
automatically appends a null character to terminate the string.
o Syntax
▪ fgets(str, sizeof(str), stdin);
• where str is the char array to which the string is stored.
• Sizeof(str) denotes the maximum number of characters
to read.
• stdin denotes the standard input stream.
• Displaying strings :
o Using printf()
printf("%s",str);
o Using puts()
puts(str);

// C program to read string from user using scanf() and display it back to
user.

#include<stdio.h>
int main()
{
// declaring string
char str[50];

printf("Enter the string: ");

// reading string without & symbol
scanf("%s",str);


S2-GXEST 204-PROGRAMMING IN C (2024 Scheme) Reenu Renjith - Assistant Professor CSE - MBITS 3

Written for

Course

Document information

Uploaded on
June 5, 2025
Number of pages
19
Written in
2024/2025
Type
Class notes
Professor(s)
Alfariz
Contains
All classes

Subjects

$3.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
alfariz

Get to know the seller

Seller avatar
alfariz Mbits
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
11 months
Number of followers
0
Documents
2
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions