пятница, 27 декабря 2013 г.

Упражнение 1.1.

Выполните программу, печатающую "здравствуй, мир", в вашей системе. Поэкспериментируйте, удаляя некоторые части программы, и посмотрите, какие сообщения об ошибках вы получите.

1. #include <stdio.h>
2. int main(void)
3. {
4.        printf("hello, world\n")
5.
6.        return 0;
7. }

$ cc -g -O0 -Wall -o a.out hello.c
hello.c: In function 'main':
hello.c:6: error: expected ';' before 'return'


1. #include <stdio.h>
2. int main(void)
3. {
4.        printf("hello, world\n
5.                        ");
6.
7.        return 0;
8. }

$ cc -g -O0 -Wall -o a.out hello.c
hello.c:4:9: warning: missing terminating " character
hello.c: In function 'main':
hello.c:4: error: missing terminating " character
hello.c:5:4: warning: missing terminating " character
hello.c:5: error: missing terminating " character
hello.c:7: error: expected expression before 'return'
hello.c:8: error: expected ';' before '}' token

2 комментария:

  1. +
    hello.c:3:5: warning: incompatible implicit declaration of built-in function ‘printf’
    hello.c:3:5: note: include ‘’ or provide a declaration of ‘printf’

    ОтветитьУдалить
  2. Вероятно, вы не подключили заголовочный файл:
    #include

    ОтветитьУдалить