Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
Where, inside of Xcode, can I input a file name for output redirection? Thanks
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
I looked where you directed me. I didn't see where or how to add redirection. ./program > output.txt Places for arguments but not redirection. Xcode 4.40
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
More online search seems to suggest that Xcode 4 has bugs which doesn't do redirection of output to a file. Can I change the directory where the exe is placed so it's not so unaccessible.
 

cqexbesd

macrumors regular
Jun 4, 2009
175
42
Germany
More online search seems to suggest that Xcode 4 has bugs which doesn't do redirection of output to a file.

I'm going to speculate here and have done no research whatsoever. With that disclaimer out of the way...

I would guess that XCode execs your binary. If you supply "> file" as an argument it will get passed to your binary. The problem is your binary probably doesn't understand "> file". When running from the command line redirection is handled by the shell before a binary is execed. In this case you probably don't have a shell so there is nothing to do the redirection.

Can I change the directory where the exe is placed so it's not so unaccessible

Probably but you other alternative is just to symlink it so it appears to be in another location. No need to play with XCode settings at all.
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
splitting a list of dates

Not sure why I can't get this but if anybody can tell me how to know when I am at the line before "stop, here" I would appreciate it. As you can see the date becomes more recent at that point. The actually dates are not important only the order. In C please. Thanks

,20050107,000000,18.2200,18.3300,18.0000,18.0800,1297,0
EWG,D,20050106,000000,18.2200,18.2500,18.0800,18.2000,1563,0
EWG,D,20050105,000000,18.1000,18.2400,18.0900,18.1900,1208,0
EWG,D,20050104,000000,18.4600,18.4800,18.1000,18.1800,1613,0
EWG,D,20050103,000000,18.5000,18.6400,18.4900,18.5500,1505,0
"Stop here"
EWG,D,20130321,000000,24.8300,25.0450,24.7900,24.8600,31938,0
EWG,D,20130320,000000,25.2500,25.3000,25.1450,25.2100,31307,0
EWG,D,20130319
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
Maybe I'm missing what the question is, but the obvious thing is to read the next line and check it for "Stop Here".

If there's not an actual line that says "Stop Here", i.e. the data is like this:
Code:
EWG,D,20050105,000000,18.1000,18.2400,18.0900,18.1900,1208,0
EWG,D,20050104,000000,18.4600,18.4800,18.1000,18.1800,1613,0
EWG,D,20050103,000000,18.5000,18.6400,18.4900,18.5500,1505,0
EWG,D,20130321,000000,24.8300,25.0450,24.7900,24.8600,31938,0
EWG,D,20130320,000000,25.2500,25.3000,25.1450,25.2100,31307,0
then the next most obvious thing is to look at the dates, or presumed dates, i.e. the 3rd field, which contains an 8-digit numeric string. There is a jump of 7 years (or 70000) at that point, which seems like it would be quite easy to detect in any of several ways (as a substring, as a parsed string, as a parsed number).

I'm not sure what you mean by the actual dates aren't important. The size of the jump is going to be important in detecting the jump. If the discontinuity is undetectable, or occurs at places that aren't stopping points, then you have ambiguous end conditions, and you need to adjust the criteria until the end conditions are unambiguous.

I assume there's currently some C code that parses the fields and converts to numbers, substrings, etc., perhaps using one of the scanf() family of functions. If so, post that code, so we know what it's doing now. If we don't know how you're parsing the presumed date now, it's difficult to give specific details.


If the question really is how to know you're at the line BEFORE the first line with a 2013xxxx value, then that's impossible. You can't know you're BEFORE any line except by reading the next line and seeing it's the line you have to stop at.

In theory you could do read-ahead (man fseek, man ftell), but that's extra logic and it seems kind of silly to do that on every line. Simply read the next line, decide if it's the stopper line, and stop if it is.


There are also tools you could use (like awk) that can split the file when it transitions from 2005xxxx to 2013xxxx, but I suspect learning awk for that alone is more than you're willing to invest.
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
I parsed out the date, I tried various comparisons but they wouldn't work or I was making some sort of stupid mistake.

Typing this I realized that I might be better off not working with strings but converting them to ints; that and the right logic worked.
Thanks.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
I parsed out the date, I tried various comparisons but they wouldn't work or I was making some sort of stupid mistake.

Without seeing code, no one can possibly tell you what that mistake was. So if you want to fix the mistake, and possibly learn how to do it correctly in the future, you'll have to post code.
 

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
This works.
Code:
fgets(firstline, 300, oldfile);
		  strcpy(hold, firstline);
		  junk = strtok (firstline,","); //symbol
			junk = strtok (NULL,","); //
			date1 = strtok (NULL,",");
					  
		do
		{
			fprintf(newfile,"%s",hold);
				
			if (isdigit(date1[0]))
				day1 = strtoul(date1, NULL, 10);
			 	else
				break;
			day2 = day1;
			fgets(firstline, 300, oldfile);
			 strcpy(hold, firstline);

			junk = strtok (firstline,","); //symbol
		 	junk = strtok (NULL,","); //
			date1 = strtok (NULL,",");
	
			if (isdigit(date1[0]))
				day1 = strtoul(date1, NULL, 10);
			 	else
				break;
			printf("%s  %s \n", date1, date2);
					
		  }
		  while( day1 < day2 );


----------

When they are not scripted languages and as fast.
 

chown33

Moderator
Staff member
Aug 9, 2009
10,740
8,416
A sea of green
This works.
Code:
...

If it works, then I have nothing to add.


You wrote this:
I parsed out the date, I tried various comparisons but they wouldn't work or I was making some sort of stupid mistake.
My suggestion applied to the "various comparisons" that didn't work, not the revised code that does work.

If you want to learn what was wrong with the code that didn't work, then you'll have to post that code.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.