Easy tool to convert data to different format [closed] - linux

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I'm studying statistics and programming on my own. What kind of C or Python program will solve the following problem in Linux?
I have a text (maybe CSV) file of the form
pcb138 pcb180 pcb52 pcb118 pcb
1,46 ,738 ,532 ,72 19,9959
,64 ,664 ,03 ,236 6,0996
3,29 1,15 ,134 1,54 24,9655
3,94 1,33 ,466 1,94 37,4436
...
32,3 31,5 1,8 8,49 318,7461
Now I would like to convert those to another format that another program understands. Namely, a text file of the form
pcb138=[1.46,0.64,3.94,...,32.3]
pcb180=[0.738,0.664, 1.15,1.33,...,31.5]
pbc52=[0.532, 0.03, 0.134, 0.466, ...,1.8]
pbc118=[0.72, 0.236, 0.154, 1.94, ...,8.49]
pbc=[19.9959, 6.0996, 24.9655, 37.4436, ...,318.7461]

Write a C program using a 2 dimensional array and strtok() to do the parsing
http://www.cplusplus.com/reference/cstring/strtok/
/* strtok example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
}

Related

Converting NodeJS byte buffer [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I'm trying to figure out how to convert NodeJS code like this:
const buffer = new Buffer(24);
offset = buffer.writeUInt32BE(this.a, offset);
offset = buffer.writeUInt32BE(this.b, offset);
offset = buffer.writeUInt8(this.c, offset);
offset = buffer.writeUInt16BE(d, e); 1 : 0, offset);
buffer.writeInt8(this.f, offset);
to Go.
I figured I could use
buffer := make([]byte, 24)
buffer[0] = a
buffer[2] = b
but this is not working
is there a recommended way to do something like this with Go?
You should use binary.ByteOrder.
So in your case, using Big Endian, something like :
package main
import (
"encoding/binary"
)
func main() {
buffer := make([]byte, 24)
// Uint32
binary.BigEndian.PutUint32(buffer, 1)
binary.BigEndian.PutUint32(buffer[4:], 2)
// Uint8
buffer[8] = 3
// Uint16
binary.BigEndian.PutUint16(buffer[9:], 4)
// Uint8
buffer[13] = 5
}

Software interrupt on network traffic [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
On my computer there is 3G, Wifi and LAN port. I would like to build a linux software to show green color if there is network traffic and red color for no network traffic.
TCPDUMP could provide the real time statistics but it would generate high CPU load. Therefore I wonder if I could get the real time statistics via software interrupt? Whenever there is network traffic a software interrupt will be generated.
Thanks in advance
I don't know whether you'd call this a software interrupt, but you could consult the following example. (The third argument to poll() is the time in milliseconds after which the network is considered inactive.)
/* compile with -lpcap */
/* run as root */
#include <stdio.h>
#include <sys/poll.h>
#include <pcap.h>
int main(int argc, char *argv[])
{
int color = 0;
struct pollfd ufd;
struct pcap_pkthdr h;
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *p = pcap_open_live(NULL, 0, 0, 0, errbuf);
if (!p) return puts(errbuf), 1;
ufd.fd = pcap_fileno(p);
ufd.events = POLLIN;
for (; ; )
switch (poll(&ufd, 1, 100))
{
case -1: perror("poll"); return 1;
case 0: if (color) color = 0, puts("red"); break;
default: if (!color) color = 1, puts("green");
pcap_next(p, &h);
}
}

Loading a Directory into a Tree Control [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
How can I load files and folders into tree control using vc++.
Is any functions available ?
If it is a windows based system you can use the Win32 API FindFirstFile, FindNextFile and FindClose functions. One small example.
If it is an MFC application you can use CFileFind class. Checkout this example from MSDN.
#include <afxwin.h>
#include <iostream>
using namespace std;
void Recurse(LPCTSTR pstr)
{
CFileFind finder;
// build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("\\*.*");
// start working for files
BOOL bWorking = finder.FindFile(strWildcard);
while (bWorking)
{
bWorking = finder.FindNextFile();
// skip . and .. files; otherwise, we'd
// recur infinitely!
if (finder.IsDots())
continue;
// if it's a directory, recursively search it
if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
}
finder.Close();
}

What programing language is this? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Someone know what kind of language used below:
String^ fileName = "C:\\Test1.txt";
array<Byte>^ Array = gcnew array<Byte>(512);
try
{
FileStream^ fs = File::OpenRead(fileName);
fs->Read(Array, 0, 512);fs->Close();
}
catch (...)
{
MessageBox::Show("Disk error");
Application::Exit();
}
and another example of that language:
int RotateLeft3 (int number)
{
if ( ( number & 0x20000000 ) == 0x20000000 )
{
number <<= 3;number |= 1;
}
else
number <<= 3;
return number;
}
Its C++ in .NET. You can tell by the use of ^ as pointer instead of *
This is C++/CLI, in other words the C++ variant that runs on top of the .Net CLR.
On no account should this be confused with native C++.
It looks like managed c++ from Microsoft.

Problems with my binary search and linear search [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I've tried using both binary search, and while loops and for loops in my searches and the same problem is occurring.
When my original program comes to this function call, the linear search function (displayContent) will always assign -1 to position, and after the function call the program breaks and exits.
I have tried to rearrange my program. Like I said, I tried for loops and while loops with both binary and linear search.
I am also using a structure data type of
struct info
{
string name;
double score[5];
double avg;
};
Here is my function call
cout<<"Please enter the name of the person which you would like to search. ";
getline(cin, name);
cin.ignore();
displayContent(contestant, count, name);
Here is my function definition
void displayContent(info contest[], int quantity, string id)
{
int position=-1;
bool found=false;
for(int index=0;index<quantity && !found;index++)
{
if(contest[index].name.compare(id)==0)
{
found=true;
position=index;
}
}
if(position==-1)
{
cout<<"That person was not one of the contestants.";
}
else
{
cout<<"The scores for "<<contest[position].name<<" are \n Contestant Judge1 Judge2 Judge3 Judge4 Judge5 Average"
<<"\n______________________________________________________________________"<<endl;
cout<<right<<setw(15)<<fixed<<setprecision(1) <<contest[position].name<<setw(10)<<contest[position].score[0]<<setw(8)<<contest[position].score[1]<<setw(8)<<contest[position].score[2]<<setw(8)<<contest[position].score[3]
<<setw(8)<<contest[position].score[4]<<setw(8)<<contest[position].avg<<endl;
}
}
Have you verified that getline does what you expect? Perhaps name contains a line ending character. To rule out problems with input you can try to assign a value to name you know exists in contestant before calling displayContent.
I haven't been able to spot any problems in your search algorithm.

Resources