strings and their use in c
output

Strings are the set of character stored in a character array likewise we store group of integers in int array. Strings are one of the most important and wide part of any programming language as Strings are often use by programmers to manipulate words and sentences.
A hacker use strings functions more frequently than other to hack passwords and break the security. There are so many algorithms based on strings For Ex Brute-Force attack algo to match strings(Passwords)
We must write a code to explore the Strings functionality:

Code:
#include<stdio.h>
int main()
{
char site[]={‘B’,’U’,’F’,’F’,’E’,’R’,’C’,’O’,’D’,’E’,”};
char x[]=”www.buffercode.in”;
int i=0,j=0;
//=======method 1=============//
while(site[i]!=’ ‘){
printf(“%c”,site[i]);
i++;
}
printf(“n”);
//=========method 2============//
while(x[j]!=’ ‘){
printf(“%c”,x[j]);
j++;
}
//========method3=====//
printf(“nn%s without loop “,x);
printf(“n%s without loopn “,site);
return 0;
}

strings and their use in c
output

Declaration Syntax:
We must define a string where we declared them FOR EX:-
char site[]={‘B’,’U’,’F’,’F’,’E’,’R’,’C’,’O’,’D’,’E’,”};

char x[]=”www.buffercode.in“;
Note: char site[25];
site=”Buffercode” is a wrong method.

Output:
It’s easy to understand the output of first two method, if you know how array works?. We just initialize a character a array and use a while loop to print the output just the thing to note is that a string ends with ‘ ‘. So rather than to using length of array as you use in array of integers to end the loop, we use .
But we rarely use these two methods frequently as printf() has a easier method to do this, which is shown in method 3
printf(“nn%s without loop “,x);
printf(“n%s without loopn “,site);
Here we use “%s” in place of “%c” because here all string is printed together not a character of string is printed at a time.
As we say in starting strings cover a wide part in any programming language ,so it is not possible to tell you all in one post. So now it is enough to know about string in this post, in our next post we know more about Strings and their functions.

Previous    C Programming    Next

NO COMMENTS