Read from file and make few things
Well I have txt files like
IP | separator | name
xxx.xxx.xx.xx, name
xxx.xxx.xx.xx, name
xxx.xxx.xx.xxx, name
I wanna read one line then execute commands from it
I'll map network drive then execute command's for copying files on that network drive then read next line from that txt and so on.
Can you help on that.
Do you have some code that I can look for.
Or we can code it together.
Well I have troubles on beggining so I heavent post any code.!
--------------
I started coding and I'll ask questions in later down posts. and here I'll edit post of code that I wroted. So you can easly join in coding. Thanks.!
For now this is done, almost nothing but heh.
Code:
// Windows Based Code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void formatIP(char*buf, char*ip,char*ipname);
void map_drive(char *ip, char *ipname);
void copyfile(char *ip, char *ipname, char *drive_path);
int main(void)
{
char ch;
char buf[BUFSIZ] = {'\0'};
char ip[15] = {'\0'};
char ipname[BUFSIZ] = {'\0'};
FILE *fpIP;
fpIP = fopen ("ip_adress_list.txt","rt");
if (fpIP!=NULL)
{
// uzmi jedan red iz adress lista
while (fgets(buf, BUFSIZ, fpIP) != NULL)
{
// formatiraj red iz adress lista ip adresa i ip name
formatIP(buf, ip, ipname);
map_drive(ip, ipname);
}
}
else
{
perror("fopen");
}
system("PAUSE");
return 0;
}
void formatIP(char*buf, char*ip,char*ipname)
{
int i, j = 0;
int separator = 0;
char ch;
for(i=0,j=0;*buf!='\0';buf++)
{
ch = *buf;
if (ch == ',')
{
separator=1;
}
if(separator != 1)
{
*(ip+i) = ch;
i++;
}
else
{
*(ipname+j) = ch;
j++;
}
}
*(ip+i)='\0';
*(ipname+j)='\0';
}
void map_drive(char *ip, char *ipname)
{
char map_dr[50] = {'\0'};
const char drive_name[3]="i:\0";
const char drive_path[3]="c$\0";
char disc_map_dr[30] = {'\0'};
char ch;
FILE *fpMD;
fpMD = fopen("map_drive.bat", "wt");
strcpy(map_dr, "net use ");
strcat(map_dr, drive_name);
strcat(map_dr, " \\\\");
strcat(map_dr, ip);
strcat(map_dr, "\\");
strcat(map_dr, drive_path);
fprintf(fpMD, "%s\nEXIT", map_dr);
fclose(fpMD);
system("map_drive.bat");
copyfiles(ip, ipname, drive_path);
//DISCONNECT MAP DRIVE
strcpy(disc_map_dr, "net use ");
strcat(disc_map_dr, drive_name);
strcat(disc_map_dr, " /delete");
system(disc_map_dr);
}
void copyfile(char *ip, char *ipname, char *drive_path)
{
}