Archive for the ‘C/C++’ Category

C Header Files Include Syntax

Tuesday, November 30th, 2010

It is very basic but this tutorial has a very clear explanation of the syntax:

#include <file>
This variant is used for system header files. It searches for a file named file in a standard list of system directories. You can prepend directories to this list with the `-I’ option (see section 12. Invocation).

#include "file
This variant is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the same directories used for <file>.

FYI: The “-I” opption is used as:

$ gcc –I path/to/header code.cpp –o output

C interview questions…

Sunday, November 30th, 2008

1. What will print out?

main()
{
        char
*p1=“name”;
        char
*p2;
        p2=(char*)malloc(20);
        memset (p2, 0, 20);
        while(*p2++ = *p1++);
        printf
(“%s\n”,p2);

}

(more…)

延迟DOS窗口界面自动关闭的方法

Wednesday, April 16th, 2008

今天开始复习(学习)C, Windows下就没什么好Complier…唉,懒得用VC++,下载了一个Dev C++的IDE.

写了个测试的程序,编译后执行,出来个DOS窗口,層的一下就闪过就没了…很烦人的Windows,会自动关闭DOS窗口…

我要复仇! 现在就和它做个了结,为我的C铺平大路…

现在来修改程序:


//muzhu.cpp
//延迟DOS界面

#include <iostream>

using namespace std;

//程序主体

int main()

{

cout <<"我们家有一头母猪和一头公猪" <<endl;

cin.get () ;

return 0;

}

程序中多了“cin.get();”而已…这样的话呢,你的程序就会乖乖地等你的Input,你不输入,它就不会完成运行,这样DOS窗口也就不会”一闪而过”了…

另外一个方法: 用Pause

How do I emulate the MS-DOS pause function?

There are two ways. You can do it this way:

#include <stdio.h>

int main()
{
  printf (”Press ENTER to continue.\n”);
  getchar (); // wait for input
  return 0;
}

Or this way:

#include <stdlib.h>

int main()
{
  system (”pause”); // execute M$-DOS’ pause command
  return 0;
}