Hi ,

A simple stupid question: I am to read the contents of a file that goes this way

RXbytes = 0 b TXbytes = 0 b
RXbytes = 3 Kb TXbytes = 2 Kb
RXbytes = 119 Kb TXbytes = 6 Kb
RXbytes = 189 Kb TXbytes = 5 Kb
RXbytes = 189 Kb TXbytes = 5 Kb
RXbytes = 189 Kb TXbytes = 5 Kb
RXbytes = 189 Kb TXbytes = 5 Kb

and gives this error: & Illegal operator for pointer 2
*** Interpreter error recovered ***

Since = is an operator, is it appropriate to specify it as char? Is it the one that causes trouble in fscanf?
Many thanks


TH1F readThroughput(char *fname, int nread) {
  char rec, trans, equal0, equal1;
  float rxThoughput, txThroughput;
  int i;
  char RXunit, TXunit;
  TH1F *h = new TH1F("h1","Throughput", nread, 0.5, nread-0.5);

  FILE *fp = fopen(fname, "r");
  if (fp == NULL) {
	printf("Cound not open file %s\n",fname);
  	return h;

  for (i=0; i<nread; i++)  {
	printf("Can you read me?");
	fscanf(fp,"%c %c %f %c %c %c %f %c" &rec, &equal0&rxThoughput, &RXunit, &trans, &equal1, &txThroughput, &TXunit);
	h->SetBinContent(i+1, rxThoughput);

  return h;
7 Years
Discussion Span
Last Post by jonsca

Hello fclopez,
You have missed some ',' in the line 16. Make sure that you didn't miss them in the program.

fscanf(fp,"%c %c %f %c %c %c %f %c" &rec, &equal0&rxThoughput, &RXunit, &trans, &equal1, &txThroughput, &TXunit);

Edited by Arbus: n/a


You are trying to read "RXBytes" into one character (since you are using %c and rec is just a character).

I would read the whole line in using fgets and copy out/parse the portions that you need based on the fact that your have an equals sign, followed by a space, followed by a number (since the text is the same each time you don't really need to keep copying it out). You're not limited to fgets, as you're using C++, so you could possibly look into using a stringstream as well.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.