School Commit Init

This commit is contained in:
2024-08-31 12:07:21 +03:00
commit 0b130ee18c
2801 changed files with 4720552 additions and 0 deletions
@@ -0,0 +1,26 @@
#include<stdio.h>
int main(){
FILE *fp;
int i,c,cnt=0;
char buff[1000];
fp=fopen("file1.txt","r");
if(fp==NULL){
perror("Error in opening file\n");
return (-1);
}
do{
for(cnt=0;(c=fgetc(fp)) != "\n" && c!=EOF;cnt++){
buff[cnt]=c;
}
buff[cnt]='\0';
for(i=cnt-1;i>=0;i--){
printf("%c",buff[i]);
}
printf("\n");
if(feof(fp)){
break;
}
}while(1);
fclose(fp);
return 0;
}
@@ -0,0 +1,18 @@
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main(){
FILE *fp;
int c;
char buff[1000];
fp=fopen("file1.txt","r");
while(1){
if(fgets(buff,1000,fp)==NULL){
break;
}
for(c=(int)strlen(buff);c>=0;c--){
printf("%c",buff[c]);
}
}
return 0;
}
@@ -0,0 +1,11 @@
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("file1.txt","w+");
fputs("The first string written",fp);
fseek(fp,4,SEEK_SET);
fputs("second",fp);
fclose(fp);
return 0;
}
@@ -0,0 +1 @@
The second string written
@@ -0,0 +1,30 @@
#include<stdio.h>
int main(){
FILE *fp;
char ch;
int length;
fp = fopen("homework.txt","r+");
if(fp == NULL){
printf("File does not exist!");
return -1;
}
while((ch = fgetc(fp)) != EOF){
if(ch >= '0' && ch <= '9'){
length++;
}
else if(ch == ' ' && length!=0){
fseek(fp,ftell(fp)-length,SEEK_SET);
fputc('|',fp);
while(length>0){
fputc('s',fp);
length--;
}
}
else
{
length=0;
}
}
fclose(fp);
return 0;
}
@@ -0,0 +1,13 @@
#include<stdio.h>
#include<stdlib.h>
int main(int argc, char const *argv[])
{
int sum;
if(argc != 3){
printf("Usage: ./3.out first_number second_number");
return -1;
}
sum = atoi(argv[1]) + atoi(argv[2]);
printf("Sum of %d and %d is %d", atoi(argv[1]), atoi(argv[2]), sum);
return 0;
}