Objectives: 1. Learn the different string functions in C-language. 2. Develop algorithms and flowcharts for use in progr

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Objectives: 1. Learn the different string functions in C-language. 2. Develop algorithms and flowcharts for use in progr

Post by answerhappygod »

Objectives 1 Learn The Different String Functions In C Language 2 Develop Algorithms And Flowcharts For Use In Progr 1
Objectives 1 Learn The Different String Functions In C Language 2 Develop Algorithms And Flowcharts For Use In Progr 1 (134.59 KiB) Viewed 23 times
Objectives: 1. Learn the different string functions in C-language. 2. Develop algorithms and flowcharts for use in programming applications. 3. Design, compile, test, run, and implement C language program Discussion: Strings • A sequence or series of characters and treated as a single data item. • Enclosed with double quotes, it includes letters, symbols, digits and control characters. • Declared as char and part of the string.h library String Functions 1. strcpy(string1, string2); -this string function copies the content of string 2 to string 1. 2. puts(string_var); -a string output function. This function displays the string value. 3. strlen(str); -this function returns the length of the string 4. strcat(str1,str2); -it appends the string2 to the end of string 1. 5. strlwr(str); -this string function converts all uppercase letters to lowercase. 6. strupr(str); --this string function converts all lowercase letters to uppercase. 7. strrev(str); - reverses all the characters in the string. 8. strcmp(str1, str2); - compares two strings. If string1>string2, the function returns a positive value; if string 1 #include int main(int argc, char *argv[]) { } char gn[10], fn[10]; strcpy(gn,"Jay"); strcpy(fn, "Roberts"); puts(gn); puts(fn); return 0; Example 2: #include #include int main(int arge, char *argv[]) ( char gn[10], fn[10]; char con[10], cfn[10]; printf("\nEnter your given name: "); gets(gn); printf("\nEnter your family name: "); gets(fn); strcpy(cgn,gn); strcpy(cfn.fn); puts(cgn); puts(cfn); return 0; }
Example 3. Determine the length of the string #include #include int main() { } char str1[20], str2[20]; int lengthst; printf("\nEnter string 1: "); gets(str1); lengthst=strlen(str1); strcpy(str2,str1); printf("\n%s",str2); printf("\n%d",lengthst); return 0; Example 4. Password using string functions #include #include } int main() { char str[10]; int c; printf("\nEnter your password: "); gets(str); c= strcmp(str,"jay1011"); if (c=0) puts("Welcome to the system!!!"); puts("Intruder detected!"); return 0; else
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply