0% found this document useful (0 votes)
110 views3 pages

Comprog Final Reviewer 1

The document reviews string and file handling functions in C. It describes 9 string functions - strlen, strupr, strlwr, strrev, strcpy, strcmp, stricmp, strncat, and strcat. It also reviews file opening/closing, and functions for writing (fprintf), reading (fscanf), and inputting strings (fputs) to files. Examples are provided for each function.

Uploaded by

Iruguin Angel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
110 views3 pages

Comprog Final Reviewer 1

The document reviews string and file handling functions in C. It describes 9 string functions - strlen, strupr, strlwr, strrev, strcpy, strcmp, stricmp, strncat, and strcat. It also reviews file opening/closing, and functions for writing (fprintf), reading (fscanf), and inputting strings (fputs) to files. Examples are provided for each function.

Uploaded by

Iruguin Angel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

-String Function Reviewer-

Header: #include <string.h>

1. strlen - returns the length of the string.


e.g
variable3=strlen(variabel1);
variable1 = 'Chicken' therefore the variable3 = 7

Note for 1,6,7: variable3 should be int

2. strupr - convert to uppercase.


e.g
strupr(variable1);
variable = 'ChIcKeN' convert to 'CHICKEN'

3. strlwr - convert to lowercase.


e.g
strlwr(variable1);
variable = 'ChIcKeN' convert to 'chicken'

4. strrev - reverse order.


e.g
strrev(variable1);
variable1 = 'Chicken' reverse to 'nekcihC'

5. strcpy - string copy.


e.g
strcpy(variable1,variable2);
variable2 = 'Sige'

After the strcpy:


variable1 = 'Sige'

6. strcmp - compare two strings. Case sensitive. Note: Returns 0 if strings are
identical.
e.g
variable3=strcmp(variable1,variable2);
variable1 = 'Ok'
variable2 = 'Ok'
Therefore the return value of variable3 = 0

7. stricmp - compare two strings. Case insensitive.


e.g
variable3=stricmp(variable1,variable2);

variable1 = 'Ok'
variable2 = 'Ok'
Therefore the return value of variable3 = 1

8. strncat - Merging 2 variables with controllable length .


e.g
strncat(variable2,variable1,1 - or more);
note: Inside of variable1 would be copy to variable2 with a length of 1 or more letters

if the strncat has 3 maximum letter length and your variable 1 and 2 have the following
letters:

variable1 = 'Chicken'
variable2 = 'Inasal'

kapag inoutput mo siya ganito lalabas


variable2 = 'InasalChi'

9. strcat - Merging 2 variables from left to right.


e.g
strcat(variable2,variable1);
note: Inside of variable1 would be copy to variable2

variable1 = 'Manok'
variable2 = 'Hatdog'

kapag inoutput mo siya ganito lalabas


variable2 = 'HatdogManok'
-File Handling Reviewer-

File Declaration: (Can Be Local and Global Declaration)


FILE *fptr;

Opening of File Code:


fptr = fopen("Sample.txt","w/r/a");
1. W - Overwrite
2. R - Read
3. A - Append / Continue

Inside of File handling


{

1. fprintf = Standard output to txt File


e.g
- fprintf(fptr,"\n%s %d",name,age);
- fprintf(fp,"\n%s %s %s %s %c",SNumber,lastname,firstname,MidI,program);

2. fputs = straight Input of Words Inside the txt File (Incase)


e.g
- fputs("This is c programming.", fp);

3. fscanf = to let out the input inside the txt file


e.g
- while(fscanf(fp,"\n%s %s %s %
%c",SNumber,lastname,firstname,MidI,&program)!=EOF)

Closing of File Code:


fclose(fptr);

You might also like