易截截图软件、单文件、免安装、纯绿色、仅160KB

C+C C×C

1.C语言中,long被存储为四个字节的补码。写一个程序,分别将这四个字节的内容取出,以16进制的方式显示在屏幕上。程序所需的long由用户从键盘输入,0表示输入结束。
程序运行效果如下:
input n: 12345678<回车>
hex: 00 BC 61 4E
input
n: -12345678<回车>
hex: FF 43 9E B2
input n: 0<回车>
bye!
#include<stdio.h>
int main()
{
long n,i,x;
printf("input n:");
scanf("%d",&n);
if(n==0)
printf("bye!\n");
else
{
printf("hex:");
for(i=0;i<8;i++)
{
if(i!=0&&i%2==0)
printf(" ");
x=((n&(0xf<<(28-4*i)))>>(28-4*i))&(0xf);
printf("%X",x);
}
printf("\n");
}
return 0;
}

2.有一行用户输入的英文句子 (长度<80,无标点,单词之间可能有多个空格)
。写一个程序,计算出句子中出现的所有单词以及单词出现的次数。要求所有找到的单词和次数都预先存储在下面这个数组中:struct tagWord
{ char word[20]; int count;} wordCount[40]; 最后再统一输出。
例如用户输入:abc   ab ab abc  abcd
输出为:
abc: 2
ab: 2
abcd: 1
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k,u,t=0,h=0;
char c;
struct tagWord
{
char word[20];
int count;
}wordCount[40];
for(i=0;i<40;i++)
{
for(j=0;j<20;j++)
{
wordCount[i].word[j]=0;
wordCount[i].count=0;
}
}
for(i=0,j=0,k=0;i<80;i++,h=0)
{
c=getchar();
if(c!=' '&&c!='\n')
{
t=0;
wordCount[j].word[k]=c;
k++;
}
else
{
if(c==' '&&t==0)
{
for(u=0;u<j;u++)
{
if(strcmp(wordCount[u].word,wordCount[j].word)==0)
{
h=1;
break;
}
}
if(h==1)
{
wordCount[u].count++;
k=0;
t=1;
continue;
}
wordCount[j].count++;
j++;
k=0;
t=1;
}
else
{
if(c==' '&&t==1)
continue;
else
{
for(u=0;u<j;u++)


相关文档:

C/C++ 笔试、面试题目大汇总


1.求下面函数的返回值( 微软)
int func(x)
{
    int countx = 0;
    while(x)
    {
          countx ++;
          x = x&(x-1);
    ......

关于简单c的词法分析器

这段源码能在linux下运行!!! 能识别小数
#include<unistd.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
/*#define  NULL          0*/
/*    自定义变量      */
#define&n ......

用C/C++程序控制环境变量

In C++, how do i go about using setenv to set the display?  I need to set it like this:
export DISPLAY=0.0
1、setenv("DISPLAY",":0.1",1);
If you're calling the xrandr functions from your C++ program, then I would expect setenv() should work for you. The 3rd argument of 1 tells setenv() to ov ......

C\C++ Notes

C的static的用法:
1.对于函数里的局部变量,改变的是它的生存周期,这个变量会一直存在,到程序结束. 函数外部访问不到这个变量.
2.对于全局的变量,改变的是它的作用范围,这个变量只在本文件内有效.其它的.c文件看不到.
   当然它的生命周期是和程序一样的 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号