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

Advanced C 10 Slip Solution

C programming

Uploaded by

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

Advanced C 10 Slip Solution

C programming

Uploaded by

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

Advanced C 10 Slip Solution

1) Write a C program to concatenate two strings using standard library function.

#include <stdio.h>

#include <string.h>

int main()

char str1[100], str2[100];

printf("Enter the first string: ");

scanf("%s",&str1);

printf("Enter the second string: ");

scanf("%s",&str2);

strcat(str1, str2);

printf("Concatenated string: %s\n", str1);

return 0;

2) Write a C program to store and display the name, rollno and fees of a student using
structure. Pass the member of structure variable to a function called display() to display the
contents.

#include <stdio.h>

// Define structure for student


struct Student {
char name[50];
int rollno;
float fees;
};

// Function to display student details


void display(struct Student student) {
printf("Name: %s\n", student.name);
printf("Roll Number: %d\n", student.rollno);
printf("Fees: %.2f\n", student.fees);
}

int main() {
// Declare a structure variable
struct Student student;

// Input student details


printf("Enter name of student: ");
scanf("%s", student.name);

printf("Enter roll number of student: ");


scanf("%d", &student.rollno);

printf("Enter fees of student: ");


scanf("%f", &student.fees);

display(student);

return 0;
}

3) Write C program to copy contents of one file to another by changing case of each alphabet
and replacing digits by *

#include <stdio.h>

int main() {
FILE *sourceFile, *destinationFile;
char ch;

sourceFile = fopen("source.txt", "r");


if (sourceFile == NULL)
{
printf("Error opening source file.\n");
return 1;
}
destinationFile = fopen("destination.txt", "w");
if (destinationFile == NULL)
{
printf("Error opening destination file.\n");
fclose(sourceFile);
return 1;
}

while ((ch = fgetc(sourceFile)) != EOF) {


if (ch >= 'a' && ch <= 'z')
ch = ch - 32;
else if (ch >= 'A' && ch <= 'Z')
ch = ch + 32;
else if (ch >= '0' && ch <= '9')
ch = '*';

fputc(ch, destinationFile);
}

// Close files
fclose(sourceFile);
fclose(destinationFile);

printf("File copied successfully.\n");

return 0;
}

You might also like