dslab1
dslab1
1. Develop a program in C for operations on strings like finding the string of length
copying two strings comparing two strings and pattern matching and replacing support
the program with function for each of the above operation don't use built in functions
#include <stdio.h>
int length = 0;
length++;
return length;
int i = 0;
if (str1[i] != str2[i]) {
i++;
}
// Function to copy one string to another
int i = 0;
destination[i] = source[i];
i++;
int i, j;
int n = string_length(str);
int m = string_length(pattern);
if (str[i + j] != pattern[j]) {
break;
}
}
int main() {
// Input strings
str1[string_length(str1) - 1] = '\0';
str2[string_length(str2) - 1] = '\0';
pattern[string_length(pattern) - 1] = '\0';
if (string_compare(str1, str2)) {
char copied_string[100];
string_copy(str1, copied_string);
if (match_index != -1) {
} else {
return 0;
2. write a C program to read the name and roll number of n students from the user and
store this data in a file.
#include <stdio.h>
#include <stdlib.h>
struct Student {
char name[50];
int rollNumber;
};
int main() {
FILE *file;
int n;
scanf("%d", &n);
if (file == NULL) {
return 1;
scanf("%d", &student.rollNumber);
// Write student data to the file
fclose(file);
return 0;