Advertisement
Adijata

izbaci BROJ iz stringa

Jul 19th, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.28 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. char * izbacivanje(char *s, char broj)
  5. {
  6.  
  7.     char novi[1000];
  8.     char* p=novi;
  9.     while(*s!='\0')
  10.     {
  11.         if(*s!=(char)(broj+48))
  12.         {
  13.  
  14.             *p++=*s;
  15.  
  16.         }
  17.         s++;
  18.  
  19.     }
  20.  
  21.     return novi;
  22.  
  23. }
  24.  
  25.  
  26.  
  27.  
  28. char* funkcija(char s[], int k)
  29. {
  30.  
  31.     char* pok=s;
  32.  
  33.     int i=0,br,cifra;
  34.     while(s[i]!='\0')
  35.     {
  36.         if(s[i]=='0'||s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9')
  37.  
  38.         {
  39.             br=0;
  40.  
  41.             while(s[i]=='0'||s[i]=='1'||s[i]=='2'||s[i]=='3'||s[i]=='4'||s[i]=='5'||s[i]=='6'||s[i]=='7'||s[i]=='8'||s[i]=='9')
  42.             {
  43.                 br*=10;
  44.                 br+=(s[i]-48);
  45.                 i++;
  46.  
  47.             }
  48.  
  49.             if(br>k)
  50.             {
  51.                 while(br!=0)
  52.                 {
  53.                     cifra=br%10;
  54.                     pok=izbacivanje(pok, (char)cifra);
  55.                     br/=10;
  56.                 }
  57.             }
  58.         }
  59.     i++
  60.     }
  61.  
  62.  
  63.     return pok;
  64. }
  65.  
  66. int main()
  67. {
  68.  
  69.     char rijec[15]= {"Neki broj 5"};
  70.  
  71.     char nova[15];
  72.     char* p=nova;
  73.  
  74.     p=funkcija(rijec,4);
  75.  
  76.     while(*p!='\0')
  77.     {
  78.         printf("%c", *p++);
  79.     }
  80.  
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement