I have something typical to do, and i am not sure how do that. Can someone help me out this!!!
I have data as follows from which what i should be doing in this is, if you observe the data closely top 2 lines of the data are all zero's and the bottom three lines are all zero's. This is what i need to find from the data. Suppose in this case the number of lines of data i have is 8 of which top 2 lines and bottom 3 lines are empty. I need to find the exact number of lines and the number of lines which contains all zero's in a line till it find some non zero value. Similar work should be done in the bottom of the data. Suppose if 4th line of the data below is all zero's i don't need that bcoz still there is data left over.
static DATA_T const lc38[]=
{
0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0xA0,0x4F,0x00
,0x00,0x40,0xAF,0x00
,0x00,0x00,0xFA,0x05
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
};
I know it's weird but what can i do, i have find it some how.
Note: There could be N number of rows and columns. And there could be N number of data's like this in a single file. I need a output file with the total number of rows and the how many top columns empty and how many bottom columns empty.
For any further clarification please post back.
Loading
VulpesPosted May 15, 2012, 9:09 AM
Karthik AgarwalPosted May 15, 2012, 10:01 AM
Karthik AgarwalPosted May 15, 2012, 7:50 AM
like follows:
Identifier 38, top = 8, bottom = 10
38 came from the line static DATA_T const lc38[]=
VulpesPosted May 15, 2012, 7:15 AM
#include "stdafx.h"
using namespace System;
using namespace System::IO;
using namespace System::Collections::Generic;
List
{
List
array
bool isCounting = false;
bool allZero = false;
int count = 0;
wchar_t startChar, endChar;
if(inReverse)
{
Array::Reverse(lines);
startChar = '}';
endChar = '{';
}
else
{
startChar = '{';
endChar = '}';
}
for each(String^ line in lines)
{
if (line->Length == 0)
{
continue;
}
else if (line[0] == startChar)
{
isCounting = true;
count = 0;
}
else if (line[0] == endChar)
{
if (inReverse && isCounting)
{
zeroCount->Add(0); // already counted in top lines
}
else
{
zeroCount->Add(count);
}
isCounting = false;
}
else if (isCounting)
{
array
allZero = true;
for each(String^ item in items)
{
if (item != "0x00")
{
allZero = false;
break;
}
}
if(!allZero)
{
isCounting = false;
}
else
{
count++;
}
}
}
if(inReverse)
{
Array::Reverse(lines);
zeroCount->Reverse();
}
return zeroCount;
}
int main(array
{
String^ filePath = "D:\\Karthik\\Font_Issue\\new\\Copy of HeiS_Ford_AL_23.txt";
array
List
List
StreamWriter ^ sw = gcnew StreamWriter("D:\\Karthik\\new\\new_total_count_details.txt");
for(int i = 0; i < topLines->Count; i++)
{
sw->WriteLine(String::Format("top = {0}, bottom = {1}", topLines[i], bottomLines[i]));
}
sw->Close();
return 0;
}
Karthik AgarwalPosted May 15, 2012, 2:27 AM
static DATA_T const lc38[]=
{
0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0xA0,0x4F,0x00
,0x00,0x40,0xAF,0x00
,0x00,0x00,0xFA,0x05
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
};
static DATA_T const lc39[]=
{
0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x10,0x40,0x00
,0x00,0x40,0xAF,0x00
,0x00,0x00,0x00,0x06
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
};
VulpesPosted May 14, 2012, 10:01 AM
Karthik AgarwalPosted May 14, 2012, 8:26 AM
temp = all_zeros;
Karthik AgarwalPosted May 14, 2012, 3:03 AM
Apart from that this code will not search for several batches in the file but it does the job only once and it will exit the search. This is not what i want i have several batches of data as i said before. If it is only small number of batches i would have counted on my own. If i am writing code you should be able to understand how many batches of those i have. For that reason i was asking the output should be written in an output file so i can have a look into that clearly. if its console window that's tough to analyze.
That too i need this ASAP.
Karthik AgarwalPosted May 11, 2012, 4:05 PM
static DATA_T const lc38[]=
{
0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0xA0,0x4F,0x00
,0x00,0x40,0xAF,0x00
,0x00,0x00,0xFA,0x05
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
};
static DATA_T const lc39[]=
{
0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x10,0x40,0x00
,0x00,0x40,0xAF,0x00
,0x00,0x00,0x00,0x06
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
,0x00,0x00,0x00,0x00
};
and so on..... I hope this is what your doubt is!
Anyway i would try out this and will update you the status.
VulpesPosted May 11, 2012, 2:54 PM
#include "stdafx.h"
using namespace System;
using namespace System::IO;
int CountEmptyLines(array
{
int count = 0;
for each(String^ line in lines)
{
array
bool allZero = true;
for each(String^ item in items)
{
if (item != "0x00")
{
allZero = false;
break;
}
}
if(!allZero) break;
count++;
}
return count;
}
int main(array
{
String^ filePath = "d:\\foxsoft\\cs3\\karthik.txt";
array
int top = CountEmptyLines(lines);
Array::Reverse(lines);
int bottom = CountEmptyLines(lines);
Console::WriteLine("Empty lines at top = {0}, bottom = {1}", top, bottom);
Console::ReadKey();
return 0;
}
However, you mentioned that there could be several such batches in the one file. If so, how would one batch be separated from the next?