使用c写的第一个hello world!

我第一次编写的helloworld.c是这样的:

#include <stdio.h>

int main(void){
    printf('Hello World!\n');
}

然后就报错了:

andymini:c andy$ vim helloworld.c 
andymini:c andy$ gcc helloworld.c 
helloworld.c:5:9: warning: multi-character character constant [-Wmultichar]
        printf('Hello World!\n');
               ^
helloworld.c:5:9: warning: character constant too long for its type
helloworld.c:5:9: warning: incompatible integer to pointer conversion passing 'int' to parameter of
      type 'const char *' [-Wint-conversion]
        printf('Hello World!\n');
               ^~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.9.sdk/usr/include/stdio.h:257:36: note: 
      passing argument to parameter here
int      printf(const char * __restrict, ...) __printflike(1, 2);
                                       ^
helloworld.c:5:9: warning: format string is not a string literal (potentially insecure)
      [-Wformat-security]
        printf('Hello World!\n');
               ^~~~~~~~~~~~~~~~
4 warnings generated.
andymini:c andy$ clear
andymini:c andy$ ll
total 40
drwxr-xr-x   5 andy  admin   170  4  1 22:28 ./
drwxrwxr-x  24 root  admin   816  4  1 22:26 ../
-rwxr-xr-x   1 andy  admin  8456  4  1 22:28 a.out*
-rw-r--r--   1 andy  admin    66  4  1 22:27 helloworld.c
-rw-r--r--   1 andy  admin     8  4  1 22:28 test1.php
andymini:c andy$ ./a.out 
Segmentation fault: 11
andymini:c andy$ vim helloworld.c 
andymini:c andy$ gcc helloworld.c 
andymini:c andy$ ll
total 40
drwxr-xr-x   5 andy  admin   170  4  1 22:29 ./
drwxrwxr-x  24 root  admin   816  4  1 22:26 ../
-rwxr-xr-x   1 andy  admin  8456  4  1 22:29 a.out*
-rw-r--r--   1 andy  admin    66  4  1 22:29 helloworld.c
-rw-r--r--   1 andy  admin     8  4  1 22:28 test1.php
andymini:c andy$ ./a.out 
Hello World!
andymini:c andy$ 

后面看原来是双引号的问题,改成了这样:

#include <stdio.h>

int main(void){
    printf("Hello World!\n");
}

就可以了!

另外发现vim可以:n test1.php 进行新文档的编写,只要是用:e test1.php或者:e helloworld.c就可以切换回刚刚的文件了,非常方便!

迫不及待的想多写点C代码了~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值