Adv Coding
Adv Coding
and file2, write a program to create a third string str3 with one
character from each array alternatively. If one string is longer than
the other, append the extra characters to str3. Write str into a
different text file called file3.
#include <stdio.h>
#include <string.h>
int main() {
FILE *file1 = fopen("file1.txt", "r");
FILE *file2 = fopen("file2.txt", "r");
char str3[200];
int i = 0, j = 0, k = 0;
while (i < len1 && j < len2) {
str3[k++] = str1[i++];
str3[k++] = str2[j++];
}
return 0;
}
Question 2: String reversal: Given an string with words separated by
empty spaces, commas or fullstops, write a program to return the
string after removing the commas and fullstops and reversing the
words in the string.
INPUT:
#include <stdio.h>
#include <string.h>
#include <ctype.h>
start = 0;
for (int i = 0; i <= j; i++) {
if (temp[i] == ' ' || temp[i] == '\0') {
end = i - 1;
while (start < end) {
char t = temp[start];
temp[start] = temp[end];
temp[end] = t;
start++;
end--;
}
start = i + 1;
}
}
strcpy(str, temp);
}
int main() {
char str[] = "hello, world. this is a test.";
reverseWords(str);
return 0;
}
Question 3:
Move all zeros to the end : Given integer array arr, return the array with all the
zeros moved to the end of the array . the relative ordering of the no zero
elements should not change
INPUT:
public class Main {
moveZerosToEnd(arr);
int nonZeroIndex = 0;
if (arr[i] != 0) {
arr[nonZeroIndex++] = arr[i];
arr[nonZeroIndex++] = 0;
OUTPUT: