c++ coding killing me to much to understand

I wrote the following code in vs2005 now i am translating it to vs2017
I cant figure it out.
The problem is string
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
String *binn;

  	  strcpy (drive1, drive );
          strcat (drive1,"\PATTERNLIST.AMI");
	      FILE *fh2 = fopen(drive1, "ab" ) ; // binary write
		  c=1;
			while (c<fp+1)
			{   
				sprintf_s(name,"fp%i",c);
				AmiVar todaya=gSite.GetVariable(name);
				c1=0;
	>>>			binn="";
				while (c1<16)
				{
					c1a=todaya.array[c4-c1];

					if (c1a!=0 && c1a!=1)
       >>>					{
						binn=binn->Concat("11",binn);
					}
					else
					{
						if (c1a==0)
						{
							        binn=binn->Concat("01",binn);
						}
						else
						{
							binn=binn->Concat("10",binn);
						}
					}				
					c1++;

				}

				c5=0;
				c3=1;
				c1=31;
				while (c1>0)
				{
					c2=Convert::ToInt32(binn->Substring(c1,1));
					if (c2==1) 
					{
						c5=c5+c3;
					}
					c3=c3*2;
					c1--;
				}
				fwrite(&c5,4,1,fh2);  
				c++;
			}
         fclose( fh2 );
		}

basically
it take a bit value of 11+10+01 create a 32 bit value convert it to interger and write it to hard disk.

I would like to know a more efficient way.
can I write bit by bit to the hard drive and will it add to the 32 read i need later.
Last edited on
What you've shown is partly C and partly C++.
You haven't shown declarations for your classes.

can I write bit by bit to the hard drive

No. You can write byte by byte, but not bit by bit.

PLEASE ALWAYS USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
the actual code is way to long. vs2017 change the string *bin command i use to concat the the string "11", "10" and "01" in to a ascii 32 char string then i convert to a 32 a 32 bit integer number and print it
What's an "ascii 32 char string"?
ASCII is a 7-bit character encoding.
Last edited on
sorry i meant just a string "110111101110011010110111011001" of 31 char
I then convert this string to integer 32 and write the result to disk. This way the value on the
will be the same for read in of my other program.

I just need a efficient way. Maybe not a string and feed to buffer

I know what i have to do i have to set the bit of a integer value
how do i walk the bits to match the above
Last edited on
Topic archived. No new replies allowed.