Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- /// 0
- /*void Prob1() {
- char rasp;
- printf("rasp = ");
- scanf("%c", &rasp);
- switch(rasp) {
- case 'a'
- }
- }*/
- /// 1
- /// A
- void EliminareLitera() {
- FILE *fin, *fout, *f;
- char lit;
- char text[100];
- int i, sfarsit;
- fin = fopen("f.in", "r");
- fout = fopen("f.out", "w");
- if(fin == NULL || fout == NULL)
- printf("Eroare deschidere fisier.");
- lit = fgetc(fin);
- fscanf(fin, "\n");
- //printf("%c\n", lit);
- while(fgets(text, 100, fin) != NULL) {
- printf("%s", text);
- for(i = 0; i < strlen(text); i++) {
- if(text[i] == lit) {
- strcpy(text + i, text + i + 1);
- i--;
- }
- }
- //printf("%s\n", text);
- fputs(text, fout);
- }
- fclose(fin);
- fclose(fout);
- }
- /// B
- void EliminareLitera2() {
- FILE *fAppend, *fRead;
- char lit;
- char text[100];
- int i, sfarsit;
- fRead = fopen("f.in", "r");
- fAppend = fopen("f.in", "a");
- if(fAppend == NULL || fRead == NULL)
- printf("Eroare deschidere fisier.");
- fseek(fRead, 0, SEEK_END);
- sfarsit = ftell(fRead);
- //printf("%d", sfarsit);
- fseek(fRead, 0, SEEK_SET);
- lit = fgetc(fRead);
- fscanf(fRead, "\n");
- printf("%c\n", lit);
- while((fgets(text, 100, fRead) != NULL) && (ftell(fRead) <= sfarsit)) {
- printf("%s", text);
- for(i = 0; i < strlen(text); i++) {
- if(text[i] == lit) {
- strcpy(text + i, text + i + 1);
- i--;
- }
- }
- //printf("%s\n", text);
- fputs(text, fAppend);
- }
- fclose(fRead);
- fclose(fAppend);
- }
- /// 2
- void InlocuireLitera() {
- FILE *f;
- char a, b;
- char text[100];
- int i, pos;
- f = fopen("f.in", "r+");
- if(f == NULL)
- printf("Eroare deschidere fisier.");
- a = fgetc(f);
- fgetc(f); /// spatiu
- b = fgetc(f);
- fscanf(f, "\n");
- printf("%c %c\n", a, b);
- char *p;
- pos = ftell(f);
- while(fgets(text, 100, f) != NULL) {
- printf("%s", text);
- /*
- p = strchr(text, a);
- while(p = strchr(p, a) != NULL) {
- p[0] = b;
- }
- */
- for(i = 0; i < strlen(text); i++)
- if(text[i] == a)
- text[i] = b;
- printf("%s\n", text);
- fseek(f, pos, SEEK_SET);
- fputs(text, f);
- fflush(f);
- pos = ftell(f);
- }
- fclose(f);
- }
- /// 3
- void ConvCase() {
- FILE *f;
- char text[100];
- int i, pos;
- f = fopen("f.in", "r+");
- if(f == NULL)
- printf("Eroare deschidere fisier.");
- pos = ftell(f);
- while(fgets(text, 100, f) != NULL) {
- printf("%s", text);
- for(i = 0; i < strlen(text); i++) {
- if(!(text[i] >= 'a' || text[i] <= 'z') &&
- !(text[i] >= 'A' || text[i] <= 'Z')) continue;
- if(text[i] >= 'a' && text[i] <= 'z')
- text[i] += 'A' - 'a';
- else text[i] -= 'A' - 'a';
- }
- printf("%s\n", text);
- fseek(f, pos, SEEK_SET);
- fputs(text, f);
- fflush(f);
- pos = ftell(f);
- }
- fclose(f);
- }
- /// 4
- void AparitiiLitere() {
- FILE *f;
- char text[100];
- int i, j;
- int ap['z' - 'a' + 2] = {0};
- f = fopen("f.in", "r+");
- if(f == NULL)
- printf("Eroare deschidere fisier.");
- while(fgets(text, 100, f) != NULL) {
- for(i = 0; i < strlen(text); i++) {
- char c = text[i];
- if(!(text[i] >= 'a' || text[i] <= 'z') &&
- !(text[i] >= 'A' || text[i] <= 'Z')) continue;
- if(text[i] >= 'a' && text[i] <= 'z')
- ap[ text[i] - 'a' ]++;
- else ap[ text[i] - 'A' ]++;
- }
- for(j = 0; j <= 'z' - 'a'; j++) {
- printf("%c ", j+'a');
- }
- printf("\n");
- for(j = 0; j <= 'z' - 'a'; j++) {
- printf("%d ", ap[j]);
- }
- printf("\n\n");
- }
- int posMax = 0;
- for(j = 0; j <= 'z' - 'a'; j++) {
- if(ap[j] > ap[posMax])
- posMax = j;
- }
- for(j = 0; j <= 'z' - 'a'; j++) {
- if(ap[j] == ap[posMax])
- printf("%c ", j + 'a');
- }
- if(ap[posMax] == 0) printf("Nu exista litere");
- fclose(f);
- /*
- */
- }
- /// 5
- void GasireCuvant() {
- FILE *f;
- char text[100], cuv[100], *p;
- int i, j;
- printf("Cuvant: ");
- scanf("%s", cuv);
- f = fopen("f.in", "r+");
- if(f == NULL)
- printf("Eroare deschidere fisier.");
- while(fgets(text, 100, f) != NULL) {
- p = text;
- while((p = strstr(p, cuv)) != NULL) {
- while(p[0] != ' ' && p != text) p--;
- if(p[0] == ' ') p++;
- while(p[0] != ' ' && p[0] != NULL){
- printf("%c", p[0]);
- p++;
- }
- printf("\n");
- }
- }
- fclose(f);
- }
- int main() {
- /*
- EliminareLitera();
- EliminareLitera2();
- InlocuireLitera();
- ConvCase();
- AparitiiLitere();
- */
- GasireCuvant();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement