Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* C programme to replace a strings spaces with %20 */
- #include <stdio.h>
- int main(void)
- {
- int i,j=0;
- char in[1000],out[1000];
- gets(in);
- for (i=0;in[i]!='\0';i++)
- {
- if (in[i] == ' ')
- {
- out[j++]='%';
- out[j++]='2';
- out[j++]='0';
- }
- /*
- WE CAN ALSO WRITE IT LIKE THAT
- if(in[i]==' ')
- {
- out[j] = '%';
- out[j+1] = '2';
- out[j+2] = '0';
- j=j+3;
- }
- */
- else
- {
- out[j]=in[i]; //it is also correct out[j++]=in[i]; then we need not to write j++; later
- j++;
- }
- }
- out[j]='\0';
- puts(out);
- return 0;
- }
Add Comment
Please, Sign In to add comment