Advertisement
sellmmaahh

Adijata-skripta-zad 54-ubaci br u string

Aug 26th, 2015
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.29 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. void unos(char *s) {
  5.     int i=0;
  6.     char c;
  7.     do {
  8.             c=getchar();
  9.             s[i]=c;
  10.             i++;
  11.        } while (c!='\n' && i<100);
  12.  
  13.        s[i-1]='\0';
  14. }
  15. int length (char *s) {
  16.     int duzina=0;
  17.     while (*(s++)!='\0') duzina++;
  18.     return duzina;
  19. }
  20.  
  21. void PretvoriBrojUString(char *s,int n) {
  22.    int br=obrni(n);
  23.     int i=0;
  24.     while (br!=0) {
  25.         s[i]=br%10+'0';
  26.       br/=10;
  27.       i++;
  28.     }
  29.     s[i]='\0';
  30.  
  31. }
  32. int obrni (int n) {
  33.     int nb=0;
  34.  
  35.     while (n!=0) {
  36.             nb=nb*10+n%10;
  37.     n/=10;
  38.     }
  39.     return nb;
  40. }
  41.  
  42. void insert(char *string, char *word, int indeks)
  43. {
  44.     int i;
  45.     for(i = length(string) + length(word); i >= indeks + length(word); i--)
  46.     {
  47.         string[i] = string[i - length(word)];
  48.     }
  49.  
  50.     for(i = 0; i < length(word); i++)
  51.     {
  52.         string[i + indeks] = word[i];
  53.     }
  54. }
  55.  
  56. void UbaciBrUString (char *s, int n) {
  57.  
  58. char broj[50];
  59. PretvoriBrojUString(broj,n);
  60. int i=0, poc, kraj, duzina=length(s);
  61. for (i=0; i<duzina; i++) {
  62.         while (s[i]!=' ') i++;
  63.         poc=i;
  64.         insert(s,broj,poc);
  65.         i+=length(broj);
  66. }}
  67.  
  68.  
  69.  
  70. int main () {
  71.     char s[100];
  72.     unos(s);
  73.     UbaciBrUString(s,123);
  74.     printf("%s", s);
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement