Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Задача 1:
- # include <stdio.h>
- # include <string.h>
- # define MAX 100
- int poz=0;
- int podniza ( char *rmv , char *str) {
- int i;
- int d1 = strlen (rmv);
- int d2 = strlen (str);
- if (d1 > d2)
- return 0;
- for (i = 0; i < d2 - d1+1; i++)
- if ( strncmp (rmv , str + i, d1) == 0){
- poz=i;
- return i;}
- return 0;
- }
- void izbrisi (char *str, char *rmv){
- int i, dolz, dolz2;
- char niza1[100], niza2[100];
- dolz = strlen(rmv);
- dolz2 = strlen(str);
- strncpy (niza1 , str , poz);
- niza1[poz] = '\0';
- strncpy (niza2 , str+poz+dolz, dolz2 - poz+dolz);
- niza2[dolz2-poz+dolz] = '\0';
- strcat(niza1,niza2);
- printf("%s e transformiranata niza", niza1);
- }
- int main () {
- char rmv[MAX], str[MAX];
- printf ("Vnesi niza:\n");
- gets (str);
- printf ("Vnesi podniza:\n");
- gets (rmv);
- if(podniza (rmv , str)){izbrisi (str, rmv);}
- else{printf("Ne e podniza!");}
- return 0;
- }
- //Задача 2:
- # include <stdio.h>
- # include <string.h>
- # define MAX 100
- int poz=0;
- int isAnagram (char *niza2 , char *niza1) {
- int i, j,ok=0;
- int d1 = strlen (niza2);
- int d2 = strlen (niza1);
- for (i = 0; i < d1; i++){
- if(!isspace(niza2[i])){
- for(j=0;j<d2;j++){
- if (niza2[i]==niza1[j] && !isspace(niza1[j])){ok=1;niza1[j]='♥';break;}
- }
- }
- if (!ok){return 0;}
- ok=0;
- }
- return 1;
- }
- int main () {
- char niza2[MAX], niza1[MAX];
- printf ("Vnesi niza1:\n");
- gets (niza1);
- printf ("Vnesi niza2:\n");
- gets (niza2);
- if(isAnagram (niza2 , niza1)){printf("E anagram!");}
- else{printf("ne e anagram");}
- return 0;
- }
- //Задача 3:
- #include <stdio.h>
- #include <stdlib.h>
- int palindrom(char s[], int duz){
- int j,i;
- for(j=0,i=duz-1;i>=0;j++,i--){
- if (s[i]!=s[j])
- return 0;
- }
- printf("palindrom!");
- return 1;
- }
- int main(int argc, char *argv[])
- {
- FILE * pFile;
- int c;
- if(argc==2) {printf("Upotrebaa: %s\n", argv[1]);}
- else{
- printf("Premnogu argumenti: %d", argc); return -1;}
- pFile=fopen (argv[1],"r");
- if (pFile==NULL) perror ("Ne se otvara voa gomnovo");
- else{
- int duz=0;
- char s[20];
- do {
- c = fgetc(pFile);
- if (isalpha(c)) {
- s[duz] = c;
- duz++;
- }
- else
- {
- palindrom(s,duz);
- duz=0;
- }
- } while (c != EOF);
- fclose (pFile);
- }
- return(0);
- }
- //Задача 4:
- #include<stdio.h>
- #include<ctype.h>
- #include<string.h>
- // ovdeka treba da stoi funkcija: void promena(drn drn)...mi se spie :*
- }
- int main(int argc, char *argv[]){
- FILE *ptr,*ptr2,*ptr3,*ptr4;
- char c,d,x,s[100];
- int i=0;
- int c;
- if(argc!=5) {
- printf("Premnogu argumenti: %d", argc); return -1;}
- ptr=ptr2=fopen(argv[1], "r");
- ptr3=ptr4=fopen(argv[2], "w");
- while(1){ // *proverka za citanje
- if((c =fgetc(ptr))==EOF)
- break;
- putchar(c);
- }
- puts(ptr);
- if((ptr=fopen(argv[1],"r"))==NULL){puts("Ne moze da se otvori datotekata");
- return -1;}
- if((ptr3=fopen(argv[2],"w"))==NULL){puts("Ne moze da se otvori datotekata");
- return -2;}
- c=argv[3];
- d=argv[4];
- // ova e kodot -.-
- while((x=fgetc(ptr))!=EOF){
- //fputc(x,ptr3);
- if(c==x){
- fputc(d,ptr3);
- } else fputc(x,ptr3);
- }
- puts(ptr3);
- fclose(ptr);
- fclose(ptr3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement