Windows下怎么用C语言获取正在运行的程序的路径

Windows下怎么用C语言获取正在运行的程序的路径,第1张

很简单:

API函数:

GetModuleFileName(模块句柄,保存的字符数组,字符数组的大小);

一般来说,要获取正在运行程序的全路径,那就在第一个参数写个0

参数2是保存的数组,获取的路径将保存在这个数组

参数三是字符数组的大小

给你一个示例程序:

#include <windowsh>

#include <stdioh>

void main()

{

char ExePlace[1024];/保存地址的数组/

GetModuleFileName(0,ExePlace,1024);/获取当前运行全路径/

puts(ExePlace);/输出获取到的路径/

}

#include <stdioh>

#include <stdlibh>

main( ) {

FILE fin;

int a[50][2];

int i;

fin = fopen("abctxt","r"); // 打开文件,按读的方式打开

for (i=0;i<50;i++)

fscanf(fin,"%d %d", &a[i][0], &a[i][1]); // 循环读

fclose(fin); //关闭文件

for (i=0;i<50;i++) printf("%d %d\n",a[i][0],a[i][1]); //输出来看看

return 0;

}

字符串处理,你逐行读入,分析哪些字符串满足html中定义的邮件地址就可以了

(这个如果有正则可以用,会很easy,不过默认的C库应该不支持)

你要分析的就是xxx@xxxxxx类型的字符串

用ReadConsoleOutputCharacterA函数,在windowsh中。

给你一个封好的函数吧,其作用是提取出窗口中第x行y列的位置的字符是什么。(如果没有东西会返回空格符号)。

#include<windowsh>

//下标从1开始,x行y列。

char GetStr(int x, int y)

{

COORD pos;

//ReadConsoleOutputCharacterA里的x和y指的是x列y行,且从0开始标号 

posX = y-1;posY = x-1;

LPSTR str;

DWORD read;

ReadConsoleOutputCharacterA(GetStdHandle(STD_OUTPUT_HANDLE), str, 1, pos, &read);

return str[0];

}

使用举例:

int main()

{

printf("kjndfgdfg\nkhgfhfhfgd\njifdgdfgg\n");

printf("1,2:%c\n",GetStr(1,2));

return 0;

}

输出为

kjndfgdfg

khgfhfhfgd

jifdgdfgg

1,2:j

# include <stdioh>

# include <stdlibh>

# include <ioh>

# include <conioh>

# include <dosh>

# include <fcntlh>

# define NUM 20

struct

{

unsigned int code ;

unsigned char dot [32];

}lib[NUM] ;

union

{

unsigned char ch[2] ;

unsigned int i ;

}ch_code ;

FILE fphz,fpin,fpout;

void drawdots (unsigned int incode,int num);

int main (int argc,char argv[])

{

int num;

int i,j ;

if (argc < 3)

{

printf("Format must be:makepoint <fileinput><fileoutput>\n");

exit(1);

}

fphz=fopen ("hzk16","rb") ;

if (fphz==NULL)

{

printf ("Can't open the chinaese library hzkl16\n");

exit(1);

}

fpin =fopen (argv[1] ,"rb") ;

if (fpin==NULL)

{

printf (" Can't open the source file:%s\n",argv[1]) ;

exit (1);

}

fpout =fopen (argv[2] ,"wt" ) ;

if(fpout==NULL)

{

printf ("Can't open or creat destination file:%s\n",argv[2]) ;

fclose (fphz) ;fclose (fpin) ;exit(1);

}

num=0 ;

while (!feof (fpin) )

{

fread (&ch_codech[1],1,1,fpin) ;

fread (&ch_codech[0],1,1,fpin) ;

lib[num]code=ch_codei;

drawdots(ch_codei,num);

fprintf (fpout,"\t0x%4x,\n",lib[num]code) ;

for (i=0;i<8;i++)

{

fprintf (fpout,"\t") ;

for (j=0;j<2;j++)

fprintf (fpout,"%02xH",lib[num]dot [i2+j]) ;

fprintf (fpout,"\n");

}

num++;

fclose(fphz) ;fclose(fpin);fclose (fpout) ;

return (0);

}

return 0;

}

void drawdots(unsigned int incode,int num)

{

unsigned int q_numb ,w_numb;long chpos;

ch_codei =incode;

q_numb=(ch_codech[1]-0xa1)&0x07f;

w_numb=(ch_codech[0]-0xa1)&0x07f;

chpos=(q_numb94+w_numb)32;

fseek(fphz,chpos,SEEK_SET);

fread (lib[num]dot,sizeof (char),32,fphz) ;

}

如果你的c编译器支持wim32 api的话,那么当前的目录有api GetCurrentDirectory取得,由GetModuleFileName可获得程序路径,从最后开始到第一个"\"结束,就是程序名。

以上就是关于Windows下怎么用C语言获取正在运行的程序的路径全部的内容,包括:Windows下怎么用C语言获取正在运行的程序的路径、如何用C语言读取txt文件中的数据到程序的数组中、求C语言课程设计 邮件地址提取程序 要求:读入一个HTML文件,把电子邮件地址提取出来,保存到文件中。等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10124139.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存