0% found this document useful (0 votes)
0 views

Advanced_C_Programming_Answers

The document provides various C programming concepts including string manipulation functions like strcat(), user-defined functions for copying and reversing strings, and checking for palindromes. It also discusses command-line arguments, their significance, and how to use them in programs. Additionally, it includes examples of programs to find the longest word, check odd/even numbers, and convert strings to uppercase or lowercase.

Uploaded by

rohinic720
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)
0 views

Advanced_C_Programming_Answers

The document provides various C programming concepts including string manipulation functions like strcat(), user-defined functions for copying and reversing strings, and checking for palindromes. It also discusses command-line arguments, their significance, and how to use them in programs. Additionally, it includes examples of programs to find the longest word, check odd/even numbers, and convert strings to uppercase or lowercase.

Uploaded by

rohinic720
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/ 2

1.

Output and Justification:

Code:

int main() {

static char s[] = "Tendulkar";

char *p;

p = &s[8]-8;

while(*p)

printf("%c", *p++);

Explanation: s[8] points to the null character '\0', so &s[8]-8 gives the address of s[0], i.e., 'T'.

The loop prints the string from the beginning till the null character. Output: Tendulkar

2. Significance of argv[0]:

argv[0] contains the name of the program being executed. It helps identify the running program in

command-line arguments.

3. Prototype and usage of strcat():

Prototype: char *strcat(char *dest, const char *src);

It appends the src string to the dest string.

4. User-defined function to copy and reverse a string:

void copyAndReverse(char *src, char *dest) {

int len = 0;

while(src[len] != '\0') len++;

for(int i = 0; i < len; i++) dest[i] = src[len - 1 - i];

dest[len] = '\0';

5. C program to display the longest word from 'n' words:

Read 'n' words in a loop and track the word with maximum length using strlen().

6. C program to check palindrome:


Compare characters from start and end moving toward the center. If all match, it's a palindrome.

7. Program to accept and search name from array of strings:

Use a loop to compare each name in the array with the search string using strcmp().

8. Command-line argument:

It allows passing parameters to main() during execution.

Advantages: flexibility, dynamic input, automation.

9. User-defined function to copy one string:

void copyString(char *src, char *dest) {

while(*src) *dest++ = *src++;

*dest = '\0';

10. Program to check odd/even using command-line:

Convert argv[1] to integer and check if number % 2 == 0.

11. Convert string to uppercase:

void toUpperCase(char *str) {

while(*str) {

if(*str >= 'a' && *str <= 'z') *str -= 32;

str++;

12. Description and syntax:

i. strlwr(): Converts string to lowercase. Syntax: char *strlwr(char *str);

ii. strupr(): Converts string to uppercase. Syntax: char *strupr(char *str);

iii. strlen(): Returns length of string. Syntax: size_t strlen(const char *str);

iv. strchr(): Finds first occurrence of character. Syntax: char *strchr(const char *str, int c);

You might also like