I've got this school assignment that I must do, but I have certain problems with it.
(I'm programming use the programing language C, btw)
[Please do not flame me, I'm new and I'm probably asking some very newbie questions :) ]
The assignment is as follows:
1) I am to make a small program that in which the user is to input some text and the program outputs the same text, but removes 'white spaces' (tabs \t, new lines \n, double spaces, etc).
2) the second assignment is basically the same this as the first one, accept the user inputs a string that represents C programing language code and removes all the comments.
The problem is I don't know how to do that. :( We've been introduced to the %s which inputs a string the user enters, but it stops on the first space and doesn't go further. I know that, but how do I enable the program to accept the whole thing, with white spaces?
For example, my program should do the following:
user input: This is a /n sample /t code .
program output: This is a sample code.
(don't worry about my program exceeding the array limit, it's not an issue here)
Alright, now here's my code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
char niz[50];
int i=0;
printf ("String plz \n");
scanf ("%s", niz);
getchar();
for (i=0; i<50; i++)
{
if ( niz[i]=='\0')
break;
printf ("%c", niz[i]);
}
printf ("\n TEST %c", niz[5]);
return 0;
}
Thanks for everyone in advance!


Sign In
Create Account

Back to top









