Created
May 29, 2015 11:44
-
-
Save darkodemic/9c0afab0039553870c5b to your computer and use it in GitHub Desktop.
unos stringa i filtriranje prema binarnom zapisu broja
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
//preprocessor | |
int main(){ | |
int M=0; | |
char S1[17]; | |
//Unost stringa i broja | |
printf("Unesite String S1: "); | |
scanf("%s",S1); | |
puts(""); | |
printf("Unesite ceo broj M: "); | |
scanf("%d",&M); | |
//Rad sa novim nizom | |
char S2[17]; | |
char *s1; | |
char *s2; | |
s1 = S1; | |
s2 = S2; | |
int one = 1; | |
while(one && *s1){ | |
if (M & one) | |
{ | |
*s2 = *s1; | |
s2++; | |
} | |
s1++; | |
one <<= 1; | |
} | |
*s2 = '\0'; | |
printf("Novi string S2: %s\n", S2); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment