BOLIVARIAN REPUBLIC OF VENEZUELA
MINISTRY OF PEOPLE'S POWER FOR EDUCATION
C.U 'FRANCISCO DE MIRANDA'
CARACAS-VENEZUELA
Member:
Nuñez Pablo ID: 14.016.565
Bernal Gerson ID: 19227332
Prof.: Carlos Alfonso
SECTION: 712
In programming, a string is a sequence of characters or a phrase.
ordered sequence of arbitrary (though finite) length of elements that
belong to a certain alphabet. In general, a string of characters is a
sequence of characters (letters, numbers or other signs or symbols).
From a programming standpoint, if no restrictions are placed on
alphabet, a string could be formed by any finite combination of everything
the game available characters (the letters from 'a' to 'z' and from 'A' to 'Z', the
numbers from '0' to '9', the blank space ' ', various symbols '!', '@', '%', etc.
In this same field (that of programming), they are normally used as a
predefined data type for words, phrases, or any other sequence of
characters. In this case, they are stored in a data vector or data matrix
of a single row (array in English).
REPRESENTATION OF CHAINS.
A string is usually represented in double quotation marks ("word"),
while a character of that string (a char in English) is usually
represented in single quotes ('p').
Example, in C:
Char c = 'a';
Char str[5] = "hello";
LANGUAGE (C).
In C, we refer to an array as a set of data all of the same type.
since the character string is a special type of array as it is a
set of char type data that ends with a null character, to this type of
strings are also known as 'ASCII-Z strings' and that is what we will be addressing
first of all.
EXAMPLE.
#include <stdio.h>
int main()
Char string [6]; /* Define a character string */
L‘
Chain[6]=0; Null character, means the end of the text
printf("The string is %s\n", string);
printf("The third letter of the string is: %c\n", cadena[2]);
A part of the string is: %s
return 0;
THE STRING VARIABLE.
It is therefore a string that can store up to six characters, taking in
it is necessary to allocate space to store the null character at the end of the
chain. The symbol %s shown in the printf() statements indicates to the system
that displays a string starting with the subscript element
zero, which in the sample code is the letter L, and continuing until finding the
null character. Note that in the printf() statements when the variable is indicated.
string without brackets indicates that the entirety of the string should be displayed, as long as
that when indicating the string variable with some value in brackets it refers to a
single element of the string, in this case we must use in the statement printf()
the %c symbol that indicates to the system to display a single character. The symbol
& specify the memory address of string[3] Compile and execute the code of
example for greater clarity on what is presented here.
EXAMPLE.
#include <stdio.h>
#include <string.h>
int main()
Char array1[17], array2[13], title[26], test[29];
strcpy(string1, "Fred Flintstone");
strcpy(cadena2, "Pablo Marmol");
strcpy(title, "- - -The Flintstones- - -");
printf("%s\n\n\n", title);
The main characters are: %s
y : %s
if(strcmp(string1, string2) > 0)
strcpy(test, string1);
else
strcpy(test, string2);
The largest string is: %s
strcpy(test, string1);
strcat(test, " and ");
strcat(test, string2);
printf("%s are neighbors\n", prueba);
return 0;}
OPERATIONS WITH STRINGS.
When considering strings as a data type, it is necessary to define (or know)
What operations can we perform with them, initially these.
they could be many and become very sophisticated, here are some of
they
ASSIGNMENT:
It consists of assigning one string to another.
EXAMPLE:
char *strcpy(char [], const char[]); # in C
string1=string2; // in C++
CONCATENATION:
It is, in general, the act of joining or linking things.
EXAMPLE:
pair = "Joshua" + " and " + "Lidia" # in Perl and PHP;
Luisa and Carmen
Luisa and Carmen
strcat(string1, string2); strcat(string1, string3); # in C (There must be
enough space in the first)