Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Wish on wishlist :)
Message
From
05/04/2003 10:22:14
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00774402
Message ID:
00774421
Views:
21
>>>
>>>Oh, OK. It was part of the download (from MSDN) version. If you go to the Task(er) (that's a joke, BTW) Pane, it's in the "New in Visual FoxPro 8.0" under the "Solution Samples". It's the next to the last sample.
>>>
>>>It'll launch a browser window with instructions. I've followed the instructions exactly, but no joy on the VB side (no need to convert to C#, BTW). If you do get a chance to try it, please let me know the results.
>>
>>You made me curious :) While got you online another dummy/silly question from me :)
>>I have a struct like this :
>>
>>struct mystruc
>>{
>>  short s1;
>>  char s2;
>>  int s3;
>>  unsigned char u1;
>>  unsigned short u2;
>>} myrecord;
>>
>>* A data file as seen in hexeditor
>>00 80 80 FF FF FF FF 80 00 80
>>
>>Want to read this at once into struc if possible at all. Something like :
>>
>>
>> mystruc arecord;
>> //...
>> fread( &arecord, sizeof( mystruc ), 1, fin );
>>
>>Not even sure I could make it understandable :)
>
>Cetin,
>
>No I don't completely understand. The question, however, that I'd ask is why is the char being declared as unsigned? AFAIK, char is neither signed or unsigned.

Oh here is the situation. There is some raw data with 123 fields per record. In header definition they used 1,2,4 width signed/unsigned data.
If it's 1 width and signed 0x80 stand for -128. And it works if I don't load the whole record buffer to struct at once but proceed with size info :
Something like :
		for(int i=0;i < ELEMS;i++)
		{
			if (bsign[i])
			{
				switch (sizes[i])
				{
				case 1:
				fread(&inbuf.s1, sizeof( char ),1,fin);
				outbuf[i] = inbuf.s1;
				break;
				case 2:
				fread(&inbuf.s2, sizeof( char ),2,fin);
				outbuf[i] = inbuf.s2;
				break;
				default:
				fread(&inbuf.s4, sizeof( char ),4,fin);
				outbuf[i] = inbuf.s4;
				break;
				}
			}
Above was tedious so my current version looks like :
	int iRecs=0,inZone = 0;
	char outbuf[(ELEMS+2)*4];
	memset(outbuf, 0,(ELEMS+2)*4);

	fseek(fin,DATASTART,SEEK_SET); // Go to beginning of data
	for(int x=0;x<4;x++)
	{
		outbuf[ELEMS*4+x]     = (nPassNumber  >> (x*8)) & 0xFF;
		outbuf[(ELEMS+1)*4+x] = (nCycleNumber >> (x*8)) & 0xFF;
	}
	struct LatLon {
		int iLat;
		int iLon;
	};
	LatLon latlon;
	while ( !feof(fin) && fread( buffer, sizeof( char ), BUF_SIZE, fin ) > 0)
	{
		memcpy(&latlon,buffer+LAT_LON_OFFSET,8);
		if ( latlon.iLat >= minlat && latlon.iLat <= maxlat &&
			latlon.iLon >= minlon && latlon.iLon <= maxlon )
		{
			inZone = 1;     // Entered in requested zone
			fputc(32,fout); // Create record
			for(int i=0, bufpos=0;i < ELEMS;bufpos += sizes[i++])
			{
				if ( sizes[i] != 4 && bsign[i] && buffer[bufpos+sizes[i]-1] & (1 << 7) )
				{
					memset(outbuf+(i*4), 0xFF,4);
				}
				memcpy(outbuf+(i*4), buffer+bufpos, sizes[i]);
			}
			fwrite(outbuf,sizeof( char ), (ELEMS+2)*4,fout);
			iRecs++;
		}
		else
		{
			if ( inZone ) // Exited requested zone
				break;
		}
	}
	fclose(fin);
	fclose(fout);
I'm lowlevel converting raw data to a VFP table - fout is the VFP table itself, 0 records initally opened in append mode (all integer fields).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Reply
Map
View

Click here to load this message in the networking platform