CMPSC 311 – Strings in C

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

flashcard set

Earn XP

Description and Tags

Vocabulary flashcards covering ASCII, storage of strings, common C string functions, safe 'n' variants, and related security concerns.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

ASCII (American Standard Code for Information Interchange)

A 7-bit character encoding standard in which each character (e.g., ‘A’ = 65) is represented by an integer value.

2
New cards

Null-terminated string

A sequence of characters in C stored as an array that ends with the byte ‘\0’ (value 0) to mark the end.

3
New cards

String literal

Text enclosed in double quotes (e.g., "hello\n") stored in a read-only memory section.

4
New cards

char *x vs. char x[]

A pointer points directly to the read-only literal, while an array contains a compiler-generated copy that can be modified.

5
New cards

sizeof(string)

Operator that returns the size (in bytes) of the declared object, not the length of the text; for pointers it returns pointer size.

6
New cards

strlen(string)

Library function that counts characters up to but not including the null terminator; returns string length.

7
New cards

Unterminated string

A character array lacking a final ‘\0’; causes undefined behavior when treated as a C string.

8
New cards

Buffer overflow

Writing past the end of an array (e.g., copying a longer string into a smaller buffer) which can corrupt memory or crash the program.

9
New cards

strcpy(dest, src)

Copies src (including null) into dest without bounds checking; dangerous if dest is too small.

10
New cards

strncpy(dest, src, n)

Copies at most n bytes; safer but may leave dest unterminated if no null appears within n bytes.

11
New cards

strcat(dest, src)

Appends src to the end of dest (after its null); assumes dest has enough space.

12
New cards

strncat(dest, src, n)

Appends at most n bytes of src to dest and adds a null terminator.

13
New cards

strcmp(s1, s2)

Lexicographically compares two strings; returns

14
New cards

strncmp(s1, s2, n)

Compares at most n bytes of two strings.

15
New cards

strchr(str, c)

Returns pointer to first occurrence of character c in str or NULL if not found.

16
New cards

strrchr(str, c)

Returns pointer to last occurrence of character c in str or NULL.

17
New cards

strstr(haystack, needle)

Finds the first occurrence of substring needle in haystack; case sensitive.

18
New cards

strcasestr(haystack, needle)

Case-insensitive version of strstr; non-standard but common.

19
New cards

sscanf(str, "format", …)

Parses formatted data from a string into provided variables; returns count of successfully read items.

20
New cards

n-variant functions

Safer versions of C string routines (e.g., strncpy, strncat, strncmp) that take a length argument to limit copying/comparing.

21
New cards

Secure C coding guideline

Best practices and APIs aimed at reducing common errors like buffer overflows when handling strings.

22
New cards

Rust

A memory-safe systems programming language recommended as an alternative to error-prone C for secure code.