amermo

odredjeno slovo, zamjeni n puta istim slovom

Feb 19th, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <ctype.h>
  5.  
  6.  
  7. void izmjeni(char* string, char znak, int n)
  8. {
  9.     char temp[100];
  10.     char* p = string;
  11.     char* q = temp;
  12.     int i;
  13.     while(*p != '\0')
  14.     {
  15.         if(*p == znak)
  16.         {
  17.             for(i=0; string[i] != '\0' && i<n-1; i++, q++)
  18.                 *q = znak;
  19.         }
  20.         *q++=*p++;
  21.     }
  22.     *q = '\0';
  23.     strcpy(string, temp);
  24. }
  25.  
  26.  
  27. int main()
  28. {
  29.     char string[] = "abc tbc";
  30.     izmjeni(string, 'b', 3);
  31.     puts(string);
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment