Data Structures, Strings, and Pointers in C

What is a Parent?

It’s a way of handling a large amount of data of the same type under one name or identifier.

Arrays: State and Data Access

Arrays are declared in a similar way, with separate brackets for each subscript. The general form of the declaration is:

type name [row_num] [num_columns];

The way to access the array elements is by using its name followed by the integer expressions for the two subscripts in square brackets.

What is a String?

A string is simply a vector of type char. It is declared in the following form:

type name [positions]

The special characteristic is that they usually contain text strings, and this is stored in the initial part of the chain.

Special Functions for String Treatment

  • strlen(): The prototype of this function is as follows:
    • unsigned strlen(const char *s);
    • Its name comes from string length, and its mission is to count the number of characters in a string, not including the '\0' end.
  • strcat() Function:
    • The prototype of this function is:
    • char *strcat(char *s1, const char *s2);
    • Its name comes from string concatenation and is used to concatenate two strings: s1 followed by s2.
  • strcmp() Function:
    • The prototype of this function is:
    • int strcmp(const char *s1, const char *s2);
    • Its name comes from string comparison and compares two strings.
    • The strcomp() function is completely analogous, except that it is case-insensitive.
  • strcpy():
    • The prototype of this function is:
    • char *strcpy(char *s1, const char *s2);
    • Its name comes from string copy and serves to copy strings.

Difference Between scanf/printf and gets/puts

The printf() function prints the output in the text, variables, and constants that are indicated.

printf("control_string");

While scanf(), in many respects, is analogous to printf() and is used to read data from standard input (keyboard). The general form of this function is the following:

scanf("%such thing", &argument);

The gets() function is used to read strings:

char sentence[100];
printf("Enter a sentence");
gets(sentence);

While the puts() function is used to print strings:

What is a Data Structure?

A data structure is a way to group a set of data of various types under the same name or identifier. It is declared as follows:

struct student {
  char name[31];
  char address[30];
  char phone[30];
};

To access the members of a structure, write the name of the structure, then a dot (.), followed by the name of the member. Example:

student.phone = 54546;

Data are assigned in the following form:

struct student new_student_class[300];

What is a Function?

Functions are subroutines of a program divided to make it more manageable and smaller. They are used to divide programs into subprograms that are called by the main program.

What is a Pointer?

A pointer is a variable that can contain the address of another variable. It must be declared or defined according to the type of data pointed to.

Declaration: int *address;

What is a File?

A file is any code for any program written in C, which is stored on a computer disk.

File Types

(No content provided in the original document. This section needs further information to be complete.)

File Variable Declaration

(No content provided in the original document. This section needs further information to be complete.)

Data Access and Storage

(No content provided in the original document. This section needs further information to be complete.)

Considerations When Working with Files

(No content provided in the original document. This section needs further information to be complete.)