ЭТО РАЗЛИЧНЫЙ ВОПРОС. ДРУГОЙ ОДИН КОНЦЕПТИЧЕСКИЙ МИН. Это просто пример.Как отформатировать введенную пользователем строку?
Так вот мой код:
main()
{
char input[150]; //Create a variable of type char named input to store user input
printf(" Enter a standard line: "); //Ask the user for some standard input
if (fgets(input, 150, stdin) == NULL) //Initiate a series of checks to make sure there is valid input
{
puts(" End-of-File or Input Error Detected. "); //If the end of the file is reached or there is a problem with input output a message
}
else if (input[0] == '\n') //If the user neglected to enter anything output a message
{
puts(" Oops! Looks like you forgot to enter something! ");
}
else
{
printf(" Here's what you entered: %s ", input); //If there is valid user input echo it back to the user
int i = 0;
while (input[i] != '\n')
{
if (input[i] = '/')
putchar("%2F");
i++
}
}
}
я должен заменить и отрегулировать входную линию соответственно путем замены определенных символов с их ASCII-код.
Например: 1. пользователь вводит: google.COM/search?client
2. Изменения программы и печатает обратно к пользователю, как: GOOGLE.com% 2FSEARCH% 3FCLIENT
Но система дает мне это длинное сообщение об ошибке при попытке скомпилировать мой код.
/home/cs/carroll/cssc0154/One/p1.c: In function 'main':
/home/cs/carroll/cssc0154/One/p1.c:41:5: warning: passing argument 1 of 'putchar' makes integer from pointer without a cast [enabled by default]
putchar("%2F");
^
In file included from /home/cs/carroll/cssc0154/One/p1.c:15:0:
/usr/include/stdio.h:580:12: note: expected 'int' but argument is of type 'char *'
extern int putchar (int __c);
Куда я иду не так?
' "% 2F"' немного длиннее, чем один символ ... –
@EugeneSh. Я это понимаю. Но я должен заменить символы типа «/» на их коды ASCII, так что это действительно не поможет. – Polly
Затем используйте правильную функцию для печати более одного символа. Вы уже использовали 'puts' и' printf'. –