Results 1 to 25 of 36
Thread: String to Char - ? C! BMP
Hybrid View
-
3rd January 2017 12:05 #1Registered User
Join Date: Aug:2007
Location:
Posts: 1,335
String to Char - ? C! BMP
, .
, .
PowerBasic, C#. . 2 C C++. .
: - ? ?
.
PowerBasic CVI, CVL, CVQ, ... MKI$, MKL$, MKQ$, ...
, C.
, .
.
.
BMP .
PowerBasic C C++ .
Pacific C DOS, Qt Creator 4.0.3 , .
DIR$("*.*") DIR$ PowerBasic, FIND_FIRST FIND_NEXT C, .
, fopen, fclose, fseek, ftell, fgetc, fgets, fputc, fputs, .
, Pacific C , .
C :
str1 long a2.Code:#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<sys.h> //#include<dir.h> #include<dos.h> #define DOS_INT 0x21 /* MS-DOS INT 21h */ struct FMATCH { char filler[21]; unsigned char attr; unsigned short time, date; unsigned long size; char name[13]; }; static void putdir(register char * filename) { register unsigned int fc; unsigned long total; union REGS inpreg, outreg; //union REGS regs; OK! struct FMATCH file; inpreg.h.ah = 0x1a; inpreg.x.dx = (unsigned) &file; int86(DOS_INT,&inpreg, &outreg); /* set DTA to file */ inpreg.h.ah = 0x4e; inpreg.x.dx = (unsigned) filename; inpreg.x.cx = 0; int86(DOS_INT,&inpreg, &outreg); /* get first match */ total = fc = 0; while (!outreg.x.cflag) { ++fc; /* increment file count */ total += file.size; /* add size to total */ printf("%s\t", file.name); if (strlen(file.name) < 8) putchar('\t'); printf("%8ld\t %d\n", file.size, file.attr); inpreg.h.ah = 0x4f; int86(DOS_INT,&inpreg, &outreg); /* get next match */ } printf("%ld bytes in %d files\n", total, fc); } main() { char str1[16];//Important for FGETS long a1; //int a2; int status; int len; char name[12]; //int disk; //char find[]="*.BMP"; //printf("%s",*find); //char dr[2]; //int b; FILE *fp;//Important for fp=FOPEN(name,"RB") chdrv("D:"); //dr=getdrv(); //b=getpid(); //printf(b); putdir("*.bmp"); printf("Type filename without suffix:"); scanf("%s",name); strcat(name,".bmp"); len=strlen(name); //disk=getcwd(0); //? mistake //printf("%s %s",disk,"\n"); printf("%s %s ",name,"->"); //test if(len>12) { printf("Please use short file name.\n"); } //name[16]="80x100-1.bmp"; //test ? //FILE *fp;//It must be at the initialisation fp=fopen(name,"rb"); if(fp==NULL) { printf("%s","File does not exists!\n"); }else { printf("%s","File is here.\n"); } fseek(fp,10,0); //SEEK #1,10 fgets(str1,4,fp); //GET$ #1,4,a3$ a1=atol(str1); //a3=CVL(a3$) //a2=stch_i(str1); printf("%s %s",str1,"\n"); //printf("%d\n",a1); //? status=fclose(fp); printf("%s %d","Status:",status); return; }
, str1 , "d&U9", 32 ineger, long 16- Pacific C.
!! Char Int.
, Qt Creator 4.0.3.
.Last edited by PET3; 3rd January 2017 at 12:40.
, ,
.
-
3rd January 2017 13:39 #2" , " - -OR-
{A64 2 4200+ E6 @ 10x295HTT, 1.5V ; RAM 3G 3-4-3-7 2T; Inno3D 8800GT 512MB; HDD 2x Hitachi 160G SATA2 RAID0; PSU custom PoV/Tagan 650W} = Fast & Cool & Quiet (Passive WC)
-
3rd January 2017 14:25 #3-==-
Join Date: Sep:2003
Location:
Posts: 6,444
-
3rd January 2017 15:06 #4Registered User
Join Date: Aug:2007
Location:
Posts: 1,335
.
:
string long . 0xFF + . , . .Code:#include<stdio.h> #include<math.h> #include<string.h> main() { char source[]="Rio"; char chr; int digit; chr=source[0]; digit=source[0]; printf("%c %s %d\n",chr,"->",digit); }Last edited by PET3; 3rd January 2017 at 15:56.
, ,
.
-
3rd January 2017 18:05 #5
256. union - 4 , 32 .
, , "123" 123Code:#include <stdio.h> #include <stdlib.h> main() { union { char s[4]; unsigned d; } s; s.d=0x6F6952; printf("%s -> %x\n",s.s,s.d); }Last edited by ined; 3rd January 2017 at 18:14.
ASRock B85 Pro4, Pentium G3240, DD3 8GB/1333MHz, 120GB SSD + 1TB + 640GB HDD
Gigabyte GV-R657OC-1GI, CM B500, ASUS 24B1S1, LCD SAMSUNG SM931BW, 173
-
5th January 2017 09:11 #6Registered User
Join Date: Aug:2007
Location:
Posts: 1,335
.
, str1 s.s s.d.
s.s=str1; . ?
. .
, , scanf .
LOCATE PowerBasic?
.
, , .
.
.
:
union -, str1 s.s s.d.Code:#include<stdio.h> #include<string.h> #include<math.h> #include<stdlib.h> #include<sys.h> //#include<dir.h> #include<dos.h> #include<time.h> #define DOS_INT 0x21 /* MS-DOS INT 21h */ struct FMATCH { char filler[21]; unsigned char attr; unsigned short time, date; unsigned long size; char name[13]; }; static void putdir(register char * filename) { register unsigned int fc; unsigned long total; union REGS inpreg, outreg; //union REGS regs; OK! struct FMATCH file; inpreg.h.ah = 0x1a; inpreg.x.dx = (unsigned) &file; int86(DOS_INT,&inpreg, &outreg); /* set DTA to file */ inpreg.h.ah = 0x4e; inpreg.x.dx = (unsigned) filename; inpreg.x.cx = 0; int86(DOS_INT,&inpreg, &outreg); /* get first match */ total = fc = 0; while (!outreg.x.cflag) { ++fc; /* increment file count */ total += file.size; /* add size to total */ printf("%s\t", file.name); if (strlen(file.name) < 8) putchar('\t'); printf("%8ld\t %d\n", file.size, file.attr); inpreg.h.ah = 0x4f; int86(DOS_INT,&inpreg, &outreg); /* get next match */ } printf("%ld bytes in %d files\n", total, fc); } static double fix(double number) { if(number<0){number=ceil(number);}else{number=ceil(number)-1;} return number; } main() { time_t rawtime; struct tm *timeinfo; char str1[16]; //size is Important for FGETS int x,y; //long a1; int a3; //long a3 ? //int a2; int date; //this is not calendar date int status; int len; char name[12]; //char drow2[]; //char frow[]; //char clr2[]; //int fstep; //int fpc; //int pix; //int fsd; //int disk; //char find[]="*.BMP"; //printf("%s",*find); //char dr[2]; //int b; FILE *fp;//Important for fp=FOPEN(name,"RB") chdrv("D:"); //dr=getdrv(); //b=getpid(); //printf(b); putdir("*.bmp"); printf("Type filename without suffix:"); scanf("%s",name); strcat(name,".bmp"); len=strlen(name); //disk=getcwd(0); //? mistake //printf("%s %s",disk,"\n"); printf("%s %s ",name,"->"); //test if(len>12) { printf("Please use short file name.\n"); } //name[16]="80x100-1.bmp"; //test ? //FILE *fp;//It must be at the initialisation fp=fopen(name,"rb"); if(fp==NULL) { printf("%s","File does not exists!\n"); }else { printf("%s","File is here.\n"); } fseek(fp,10,0); //SEEK #1,10 fgets(str1,4,fp); //GET$ #1,4,a3$ a3=((str1[3]*256+str1[2])*256+str1[1])*256+str1[0]; //a3=CVL(a3$) printf("%s %s",str1,"\n"); printf("%d\n",a3); fseek(fp,18,0); //SEEK #1,18 fgets(str1,2,fp); //GET$ #1,2,x$ x=str1[1]*256+str1[0]; //x=CVI(x$) printf("%d\n",x); fseek(fp,22,0); //SEEK #1,22 fgets(str1,2,fp); //GET$ #1,2,y$ y=str1[1]*256+str1[0]; //y=CVI(y$) printf("%d\n",y); date=x*y-x; printf("%d\n",date); //this is not calendar date time(&rawtime); timeinfo=localtime(&rawtime); printf("%d%s%d\n",timeinfo->tm_min,":",timeinfo->tm_sec); printf("%f\n",fix(8.5)); //test status=fclose(fp); printf("%s %d","Status:",status); return; }
.Last edited by PET3; 5th January 2017 at 10:03.
, ,
.




Reply With Quote

Lenovo ThinkPad 15 IdeaPad 15
5th May 2023, 22:16 in