当前位置:首页 > 代码 > 正文

c语言读取g代码(g++编译c)

admin 发布:2022-12-19 18:30 168


今天给各位分享c语言读取g代码的知识,其中也会对g++编译c进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

C语言读取特定内容格式地文本文件

使用链表做,文件的记录条数无法确定,数组做有限制

#include stdio.h

#include stdlib.h

#include string.h

#define LINE_COUNT 4096

#define LINE_PART1 32

#define LINE_PART2 128

#define G01_ARRAY "G01"

#define G02_ARRAY "G02"

typedef struct G01

{

int linenum;

float x;

float y;

}G01;

typedef struct G01_node

{

G01 g01;

struct G01_node *pg01_node;

}G01_node;

typedef struct G01_list

{

G01_node *pg01_first;

G01_node *pcurr_node;

int size;

}G01_list;

typedef struct G02

{

int linenum;

float x;

float y;

float i;

float j;

}G02;

typedef struct G02_node

{

G02 g02;

struct G02_node *pg02_node;

}G02_node;

typedef struct G02_list

{

G02_node *pg02_first;

G02_node *pcurr_node;

int size;

}G02_list;

int parseG01String(char *linecontent, G01_list *arr);

int parseG02String(char *linecontent, G02_list *arr);

int parseString(char *linecontent);

G02_list pg02_list = {NULL, 0};

int errorcounter_g02 = 0;

G01_list pg01_list = {NULL, 0};

int errorcounter_g01 = 0;

int currnum = 0;

int main(int argc, char **argv)

{

if(argc!=2)

{

printf("??????\n");

return -1;

}

FILE *fs = NULL;

if(!(fs = fopen(argv[1], "r+")))

{

printf("??????\n");

return -1;

}

char linecontent[LINE_COUNT] = {0};

while(fgets(linecontent, LINE_COUNT, fs))

{

//printf("%s:the linecontent is:%s\n", __FUNCTION__, linecontent);

++currnum;

parseString(linecontent);

}

printf("the result is:\n");

printf("G01 array counter:%d, follow data is\n", pg01_list.size);

G01_node *ptemp1 = pg01_list.pg01_first;

while(ptemp1)

{

printf("line:%d\t(%.3f\t, %.3f)\n", ptemp1-g01.linenum, ptemp1-g01.x, ptemp1-g01.y);

ptemp1 = ptemp1-pg01_node;

}

printf("\n\nG01 array counter:%d, follow data is\n", pg02_list.size);

G02_node *ptemp2 = pg02_list.pg02_first;

while(ptemp2)

{

printf("line:%d\t(%.3f\t, %.3f\t, %.3f\t, %.3f)\n", ptemp2-g02.linenum, ptemp2-g02.x, ptemp2-g02.y, ptemp2-g02.i, ptemp2-g02.j);

ptemp2 = ptemp2-pg02_node;

}

return 0;

}

//return: -1:paremeter is null, -2:format of paremeter is invalid, -3:mem alloc fail, 0: success

int parseG01String(char *linecontent, G01_list *arr)

{

int ret = 0;

if(!linecontent)

{

return -1;

}

G01_node *p1 = (G01_node*)malloc(sizeof(G01_node));

memset((void *)p1, 0, sizeof(G01_node));

if(!p1)

{

return -3;

}

if(sscanf(linecontent, "X%f Y%f", p1-g01.x, p1-g01.y) != 2)

{

ret = 2;

free((void *)p1);

p1 = NULL;

}

else

{

p1-g01.linenum = currnum;

if(!arr-size)

{

arr-pg01_first = p1;

arr-pcurr_node = p1;

}

else

{

arr-pcurr_node-pg01_node = p1;

arr-pcurr_node = arr-pcurr_node-pg01_node;

}

++(arr-size);

}

if(ret != 0)

{

printf("%s:linecontent in %d:%s error.\n", __FUNCTION__, currnum, linecontent);

}

return ret;

}

//return: -1:paremeter is null, -2:format of paremeter is invalid, -3:mem alloc fail, 0: success

int parseG02String(char *linecontent, G02_list *arr)

{

int ret = 0;

if(!linecontent)

{

return -1;

}

G02_node *p1 = (G02_node*)malloc(sizeof(G02_node));

memset((void *)p1, 0, sizeof(G02_node));

if(!p1)

{

return -3;

}

if(sscanf(linecontent, "X%f Y%f I%f J%f", (p1-g02.x), (p1-g02.y), (p1-g02.i), (p1-g02.j)) != 4)

{

//printf("%s:linecontent in %f:%f:%f:%f .\n", __FUNCTION__, p1-g02.x, p1-g02.y, p1-g02.i, p1-g02.j);

ret = 2;

free((void *)p1);

p1 = NULL;

}

else

{

p1-g02.linenum = currnum;

if(!arr-size)

{

arr-pg02_first = p1;

arr-pcurr_node = p1;

}

else

{

arr-pcurr_node-pg02_node = p1;

arr-pcurr_node = arr-pcurr_node-pg02_node;

}

++(arr-size);

}

if(ret != 0)

{

printf("%s:linecontent in %d:%s error.\n", __FUNCTION__, currnum, linecontent);

}

return ret;

}

//return: -1:paremeter is null, -2:format of paremeter is invalid, 0: success

int parseString(char *linecontent)

{

int ret = 0;

if(!linecontent)

{

return -1;

}

char linepart1[LINE_PART1] = {0};

char linepart2[LINE_PART2] = {0};

if(sscanf(linecontent, "%s", linepart1) != 1)

{

return -2;

}

char *pchar = strstr(linecontent, linepart1) + strlen(linepart1);

while(*pchar == ' ' || *pchar == '\t')

pchar++;

strcpy(linepart2, pchar);

//printf("%s:%s -- %s\n", __FUNCTION__, linepart1, linepart2);

if(!strcmp(G01_ARRAY, linepart1))

{

if(ret = parseG01String(linepart2, pg01_list))

{

return ret;

}

}

else if(!strcmp(G02_ARRAY, linepart1))

{

if(ret = parseG02String(linepart2, pg02_list))

{

return ret;

}

}

else

{

if(ret != 0)

{

printf("%s:linecontent in %d:%s error.\n", __FUNCTION__, currnum, linecontent);

}

return -2;

}

return ret;

}

使用:

uc: ./a.out 1.txt

vc: 1.exe 1.txt

执行程序和文本放在同一个目录内

1.txt文本内容

G02 X-26.414 Y21.386 I28.448 J-18.611

G01 X-23.305 Y18.869

G02 X25.585 Y15.659 I23.311 J-18.877

G01 X27.153 Y12.745

G02 X19.932 Y-22.369 I-26.992 J-12.749

求一个C语言中文件的读取与文件的存储的代码示范

/*读取文件*/

#include stdio.h

main()

{

    FILE *fp; /*定义一个指向FILE类型结构体的指针变量*/

    char ch, filename[50]; /*定义变量及数组为字符型*/

    printf("please input file`s name;\n");

    gets(filename); /*输入文件所在路径及名称*/

    fp = fopen(filename, "r"); /*以只读方式打开指定文件*/

    ch = fgetc(fp); /*fgetc函数带回一个字符赋给ch*/

    while (ch != EOF) /*当读入的字符值等于EOF时结束循环*/

    {

        putchar(ch); /*将读入的字符输出在屏幕上*/

        ch = fgetc(fp); /*fgetc函数继续带回一个字符赋给ch*/

    }

    fclose(fp); /*关闭文件*/

}

/*将内容写入文件*/

#include stdio.h

main()

{

    FILE *fp; /*定义一个指向FILE类型结构体的指针变量*/

    char ch, filename[50]; /*定义变量及数组为字符型*/

    printf("please input filename:\n");

    scanf("%s", filename); /*输入文件所在路径及名称*/

    if ((fp = fopen(filename, "w")) == NULL) /*以只写方式打开指定文件*/

    {

        printf("cannot open file\n");

        exit(0);

    }

    ch = getchar(); /*fgetc函数带回一个字符赋给ch*/

    while (ch != '#') /*当输入"#"时结束循环*/

    {

        fputc(ch, fp); /*将读入的字符写到磁盘文件上去*/

        ch = getchar(); /*fgetc函数继续带回一个字符赋给ch*/

    }

    fclose(fp); /*关闭文件*/

}

有了灰度图怎么用C语言编写G代码

/*也不知道你是什么级别的,我是一个新手,刚接触编程语言,以下是我自己变得一个小程序,在所有c语言的编译器(vc++6.0、turbo…………)上都能运行,你还可以进一步改进。这是一个类似贪吃蛇的小游戏。祝你好运*//*贪吃蛇*/#include#include#include#includeinthead=3,tail=0;intmain(){inti,j,k=0;intzuobiao[2][80];longstart;intdirection=77;intgamespeed;inttimeover;intchange(charqipan[20][80],intzuobiao[2][80],chardirection);zuobiao[0][tail]=1;zuobiao[1][tail]=1;zuobiao[0][1]=1;zuobiao[1][1]=2;zuobiao[0][2]=1;zuobiao[1][2]=3;zuobiao[0][head]=1;zuobiao[1][head]=4;/*处理棋盘*/charqipan[20][80];//定义棋盘for(i=0;i20;i++)for(j=0;j80;j++)qipan[i][j]='';//初始化棋盘for(i=0;i80;i++)qipan[0][i]='_';for(i=0;i20;i++)qipan[i][0]='|';for(i=0;i20;i++)qipan[i][79]='|';for(i=0;i80;i++)qipan[19][i]='_';qipan[1][1]=qipan[1][2]=qipan[1][3]='*';//初始化蛇的位置qipan[1][4]='#';printf("ThisisagameofaSNAKE.\nGOODLUCKTOYOU!\n");printf("Inputyourgamespeed,please.(e.g.300)\n");scanf("%d",gamespeed);while(direction!='q'){system("cls");for(i=0;i20;i++)//打印出棋盘for(j=0;j80;j++)printf("%c",qipan[i][j]);timeover=1;start=clock();while(!kbhit()(timeover=clock()-start=gamespeed));if(timeover){getch();direction=getch();}elsedirection=direction;if(!(direction==72||direction==80||direction==75||direction==77)){return0;system("cls");printf("GAMEOVER!\n");}if(!change(qipan,zuobiao,direction)){direction='q';system("cls");printf("GAMEOVER!\n");}}return0;}intchange(charqipan[20][80],intzuobiao[2][80],chardirection){intx,y;if(direction==72)x=zuobiao[0][head]-1;y=zuobiao[1][head];if(direction==80)x=zuobiao[0][head]+1;y=zuobiao[1][head];if(direction==75)x=zuobiao[0][head];y=zuobiao[0][head]-1;if(direction==77)x=zuobiao[0][head];y=zuobiao[1][head]+1;if(x==0||x==18||y==78||y==0)return0;if(qipan[x][y]!='')return0;qipan[zuobiao[0][tail]][zuobiao[1][tail]]='';tail=(tail+1)%80;qipan[zuobiao[0][head]][zuobiao[1][head]]='*';head=(head+1)%80;zuobiao[0][head]=x;zuobiao[1][head]=y;qipan[zuobiao[0][head]][zuobiao[1][head]]='#';return1;}

怎么用c语言实现g代码编译

同问啊,数控编程啊,难道在超级终端输入一个G代码让ARM在里面识别,再插补?

求C语言内存数据读取代码

#includestdlib.h

#includestring.h

int copymem(void*souceptr,void*destptr,int infolen)

{

return memcpy(destptr,souceptr,infolen);// 复制源去目标地址,位数为Infolen

}

关于c语言读取g代码和g++编译c的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/17579.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载