C – Strings – GENCOR

C – Strings

Strings are actually one-dimensional array of characters terminated by a nullcharacter ‘\0’. Thus a null-terminated string contains the characters that comprise the string followed by a null.

The following declaration and initialization create a string consisting of the word “Hello”. To hold the null character at the end of the array, the size of the character array containing the string is one more than the number of characters in the word “Hello.”

char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};

If you follow the rule of array initialization then you can write the above statement as follows −

char greeting[] = "Hello";

Following is the memory presentation of the above defined string in C/C++ −

String Presentation in C/C++

Actually, you do not place the null character at the end of a string constant. The C compiler automatically places the ‘\0’ at the end of the string when it initializes the array. Let us try to print the above mentioned string −

#include <stdio.h>

int main () {

   char greeting[6] = {'H', 'e', 'l', 'l', 'o', '\0'};
   printf("Greeting message: %s\n", greeting );
   return 0;
}

When the above code is compiled and executed, it produces the following result −

Greeting message: Hello

C supports a wide range of functions that manipulate null-terminated strings −

S.N. Function & Purpose
1 strcpy(s1, s2);

Copies string s2 into string s1.

2 strcat(s1, s2);

Concatenates string s2 onto the end of string s1.

3 strlen(s1);

Returns the length of string s1.

4 strcmp(s1, s2);

Returns 0 if s1 and s2 are the same; less than 0 if s1<s2; greater than 0 if s1>s2.

5 strchr(s1, ch);

Returns a pointer to the first occurrence of character ch in string s1.

6 strstr(s1, s2);

Returns a pointer to the first occurrence of string s2 in string s1.

The following example uses some of the above-mentioned functions −

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

int main () {

   char str1[12] = "Hello";
   char str2[12] = "World";
   char str3[12];
   int  len ;

   /* copy str1 into str3 */
   strcpy(str3, str1);
   printf("strcpy( str3, str1) :  %s\n", str3 );

   /* concatenates str1 and str2 */
   strcat( str1, str2);
   printf("strcat( str1, str2):   %s\n", str1 );

   /* total lenghth of str1 after concatenation */
   len = strlen(str1);
   printf("strlen(str1) :  %d\n", len );

   return 0;
}

When the above code is compiled and executed, it produces the following result −

strcpy( str3, str1) :  Hello
strcat( str1, str2):   HelloWorld
strlen(str1) :  10

I am happy to be here in Gencor which provided me with technical professional and skillful aspects of auto cad, thank you.

Kush Prakash - West Bengal University of Technology

I completed CCNA traning and certification preparation before appearing for ccna global examination 200-120 from gencor.

Amit Kumar - Lovely Professional University

The trainer has good knowledge of the subject.

Saurabh Kumar Suman - Shaheed Bhagat Singh State Technical Campus, Ferozepur

This institute is the best institute in web designing. Trainer sir is good in knowledge and best trained and  provided web designing knowledge to me.

Abhishek Kumar - Guru Gobind Singh Polytechnic College, Talwandi Sabo, (Bhathinda) Punjab

The trainer is good, so I think everything is good. 

Rabindra Kumar Yadav - Samalkha Group of Institutions

The Gencor classes is good for getting the knowledge. The trainer has good communication with students. I completed CAD training in Mechanical from here.

Akash Kumar - Jawaharlal Nehru Technological University, Hyderabad

I gained a lot here in the Gencor and I believe that it will help to enhance my knowledge and personalty further in my life.

Prem Kumar - BIT Sindri

Institute Completed my training as per  Syllabus provided on time. 

Akshay Kumar - The Institution of Civil Engineers, Delhi

Gencor institute is the best institute which completed my course on Civil CAD on time.

Amit Kumar - Reg No - 001/15348 - Civil CAD

The overall system of teaching is favorable and good as I expected and helped a lot in increasing my knowledge.

Sunny Kumar

I appreciate the course by the institute and efforts put in to complete it within the prescribed time limits.

Mohammad Asad Eqbal

The trainer has good knowledge of autocad, so I am happy to complete the training of AutoCAD from here.

Hemant Raj - Reg No.: 001/15307 - Civil CAD

The Trainer is nice one. He teaches well. The institute is good. I have faith on the Institute.

Vikash Kr Mandal - Reg No.: 001/15308 - Mechanical CAD

The institute is very good one and object oriented, focused on setting  up career for engineering students. The trainer is having enough knowledge to guide students.Teaching method is very much appreciated and interactive.

Indranil Mazumdar - Reg No.: 001/15312 - Civil CAD

All class I did here was very good. Faculty provide every detail about syllabus & Course. I am thankful of you.

Sumank Saurav - Reg No.: 001/15321 - Mechanical CAD

Trainer is the best guide for autocad and institute is also best for autocad

Vikash Kumar Sharma - Reg No.: 001/15322 - Mechanical CAD

This is professional institute , It has given the full knowledge of the subject, It is best best providing knowledge.

Dinu Kumar - Reg No.: 001/15328 - AutoCAD ME

This institute given me knowledge about Autocad and I appreciate that . I must recommend other to learn CAD from here.  

Abhishek Kr Singh (Reg No . 001/15332)

I am Gracy Pradhan , completed my  Linux training on RHCE from GenCor. Training is fully practical based and full syllabus coverage prescribed RED Hat Inc. . This training is surely going to provide me help in placement by college.

Gracy Pradhan - Ram Krishna Dharmarth Foundation University

I completed my Autocad Civil Training with Project and certification from GenCor InfoEdge – India, Trainer is The best in providing training .

Sonu Kumar

Best Training for telecommunication on Cisco CCNA. I got placed in 3i infotech Patna.