Advertisement
Adijata

izbaci broj iz stringa veci od k, pazit na negativne

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