IT3220 - C programming introduction

0.0(0)
studied byStudied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/17

encourage image

There's no tags or description

Looks like no tags are added yet.

Last updated 12:32 PM on 1/22/26
Name
Mastery
Learn
Test
Matching
Spaced
Call with Kai

No analytics yet

Send a link to your students to track their progress

18 Terms

1
New cards

library

#include <stdio.h>

#include <string.h>

#include <ctype.h>

#include < math.h>

2
New cards

check letter/ digit

  • isdigit () → digit

  • isalpha () → letter

  • isupper () → uppercase

  • islower () → lowercase

  • isalnum () → letter/ digit

→ not digit: !isdigit()

3
New cards

convert a digit character into its numeric value

( s[0] - ‘0’ )

4
New cards

scanf for string

for ( int i = 0 ; i < N ; i++ ) {

scanf ( "%d", &height[ i ] );

}

5
New cards

order from smallest to largest

for ( int i = 0 ; i < N ; i++ ) {

for ( int j = i + 1 ; j < N ; j++ ) {

if ( height[ i ] > height[ j ]) {

int temp = height[ i ];

height[ i ] = height[ j ];

height[ j ] = temp;

}

}

6
New cards

find min & max

int max = height[ 0 ];

int min = height[ 0 ];

int sum = height[ 0 ];

for ( int i = 1 ; i < N ; i++ ) {

if ( height[ i ] > max )

max = height[ i ];

else if ( height[ i ] < min )

min = height[ i ];

sum += height[ i ];

}

7
New cards

fgets in multidimensional array

for ( int i = 0 ; i < n ; i++ ) {

fgets ( name[ i ] , LEN , stdin );

name[ i ] [ strcspn ( name[ i ], "\n" ) ] = 0;

}

8
New cards

remove in string

char remove [ LEN ];

strcpy( remove, query + 7 ) ;

9
New cards

locate a substring in a string

if ( strstr ( address [ i ], remove ) != NULL )

10
New cards

element not null

s [ i ] != ‘ \0 ’

11
New cards

find frequency of number

int freq [ 100 ] = { 0 } ;

for ( int i = 0; s [ i ] != ' \0 '; i++) freq [ s [ i ] - ' 0 '] ++ ;

12
New cards

lowercase a string

void lowercase ( char s[ ] ) {

for ( int i = 0; s [ i ] ; i++) s[ i ] = tolower ( ( unsigned char ) s [ i ] );

};

13
New cards

compare two strings

strcmp(second1, "area") == 0

14
New cards

copy a string

strcpy ( min2 , name [ i ] ) ;

15
New cards

parse a log line

char line [ MAX ] ;

char id [ MAX ] [ LEN ] , plate [ MAX ] [ LEN ] , date [ MAX ] [ LEN ] , tim [ MAX ] [ LEN ] ;

int n = 0;

while ( fgets ( line , MAX , stdin )) {

line [ strcspn ( line, "\n" ) ] = 0 ;

if ( line [ 0 ] == ‘#’ ) break ;

// parse each log line

sscanf ( line , "%s %s %s %s", id [ n ] , plate [ n ] , date [ n ] , tim [ n ] ) ;

n++;

}

16
New cards

not count repetition

int count = 0;

char repeat [ MAX ] [ LEN ] ;

for ( int i = 0; i < n; i++ ) {

if ( strcmp ( findDate, date [ i ] ) == 0 ) {

int exist = 0;

for ( int j = 0; j < count; j++) {

if ( strcmp ( repeat [ j ] , plate [ i ] ) == 0) {

exist = 1;

break;

}

}

if (exist == 0) {

strcpy ( repeat [ count ], plate [ i ] );

count++;

}

}

}

17
New cards

eliminate input not letter or whitespace

int invalid ( char s [ ] ) {

for ( int i = 0; s [ i ] != '\0'; i++ ) {

if ( !isalpha ( ( unsigned ) s [ i ] ) && s [ i ] != ' ' ) return 1;

}

return 0;

} ;

18
New cards

find frequency of string

int count [ MAX ] = { 0 } ;

for ( int i = 0; i < m; i++ ) {

if ( count [ i ] ) continue;

int freq = 1;

for ( int j = i + 1; j < m; j++ ) {

if ( strcmp ( first [ i ], first [ j ]) == 0 ) {

freq ++;

count [ j ] = 1;

}

}

printf ("%s %d\n", first [ i ], freq) ;

}