English 中文(简体)
C program (malloc) is not codification in ubuntu 11.04
原标题:C program(malloc) is not compiling in ubuntu 11.04

我已经从这个<代码>上安装了电离层成像仪。 指挥

我的方案法典

 #include<stdio.h>

 main()
   {
      int *b;

      b = (int*)malloc(10*sizeof(int));  

      printf("b=%u

",b);
      printf("b+1=%u

",(b+1));
      printf("b+2=%u

",(b+2));

      b[2]=4;
      printf("*(b+2)=%d

",*(b+2));

  }

when i try to compile this program from cc -c program.c command then i get some error

“entergraph

最佳回答

您重新缺失<代码>#include <stdlib.h> (malloc),格式说明是错误的。 使用<代码>%p至打印机。

另外,你不需要(,而且可能还有tn t)表示出 Smalloc(C)。

<代码>main没有参数的正确签名是:

int main(void)

更正代码:

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int *b;

    b = (int*)malloc(10*sizeof(int));

    printf("b=%p

",  (void*) b);
    printf("b+1=%p

",(void*) (b+1));
    printf("b+2=%p

",(void*) (b+2));

    b[2]=4;
    printf("*(b+2)=%d

",*(b+2));

    return 0;
}
问题回答

我不知道它为什么在录像中工作,它很可能使用一些奇怪的非标准编辑。

但是,你的错误是,因为你正在使用暗中,而不是未经签字的,而你在期望不签字时,会通过点子打印。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签