Zum Hauptinhalt springen
••••••
Sicherheitslücken (CVE)CVE-2026-85153 | Schmooze App hard-coded credentials(06.10.2026 um 11:06 Uhr)
•••
Sichere ProgrammierungApple macht Screenshots für iPhone Duo künftig zur Pflicht(06.10.2026 um 11:00 Uhr)
•••••••
Sicherheitslücken (CVE)CVE-2026-85153 | Schmooze App hard-coded credentials(06.10.2026 um 11:06 Uhr)
•••
Sichere ProgrammierungApple macht Screenshots für iPhone Duo künftig zur Pflicht(06.10.2026 um 11:00 Uhr)
•
Intelligence View
⚡ tsecurity.de Intelligence

String in C programming.

String is a collection of characters that are used to represent textual data. int main() { char str[] = "Sujith"; printf("%s", str); return 0; } Use %s format…

Beitrag
0
Seite
0
↗ Quelle (dev.to)
Social ReaktionenReagiere als Erste:r — dein Feedback zählt!

String is a collection of characters that are used to represent textual data.




int main() {
char str[] = "Sujith";
printf("%s", str);
return 0;
}







  • Use %s format specifier for printing string.

  • Every string in c ends with \0. This null character helps the compiler to know the end of the string. So actual size of the string will be 1 greater than the total no;of character in the string.






String Input






int main() {

char str[20];

printf("Enter your name here: ");

scanf("%s", str);

printf("%s", str);

return 0;
}






In order to take the input, we don't need to use & for string because str is an array and it already points to the first element of str.



The scanf method can only take input until it encounters white spaces. So not possible to take input like "Steve Jobs". So to take all the inputs we can use:

fgets(str, sizeof(str), stdin)

str - string name

sizeof(str) - size of string.

stdin - it means standard input. It denotes we are taking input from the keyboard.






Access characters of string






int main() {

char str[] = "Sujith";

printf("%c", str[0]);

return 0;
}






Since we are only printing single character use %c format specifier






Changing elements of a string.






int main() {

char str[] = "Sujith";

str[2] = 'J';
str[4] = 'T';

printf("%s", str);
return 0;
}


Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten String in C programming.

Thematisch verwandte Begriffe: String, programming · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

💬 Kommentare werden geladen…
Zum Aktualisieren ziehen
Nächster Beitrag