searching for a file, writing to a different file and Unix.

  • (2 Pages)
  • +
  • 1
  • 2

18 Replies - 1227 Views - Last Post: 24 October 2011 - 04:40 PM Rate Topic: -----

#16 Okysho   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 96
  • Joined: 09-February 11

Re: searching for a file, writing to a different file and Unix.

Posted 24 October 2011 - 04:12 PM

Sample input:

100 Doe John 15000
101 Liu Peter 12500
102 Kim Anna 12800
103 Ali Abbas 14800

sample output:

100 John Doe 15000.00
101 Peter Liu 12500.00
102 Anna Kim 12800.00
103 Abbas Ali 14800.00

I'm pretty sure my algorithm is correct. Again, according to some of my debug tests, the Abort occurs after reading the first line.
Was This Post Helpful? 0
  • +
  • -

#17 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: searching for a file, writing to a different file and Unix.

Posted 24 October 2011 - 04:25 PM

When I ran this program through my debugger the problem was detected on line 61:
				while(strptr !=NULL)
				{
					strcpy(tokens[j], strptr); // 61


At this point you have never initialized j.

Jim
Was This Post Helpful? 0
  • +
  • -

#18 Okysho   User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 96
  • Joined: 09-February 11

Re: searching for a file, writing to a different file and Unix.

Posted 24 October 2011 - 04:31 PM

That's part of the string tokenization. It's odd since singling out the code it doesn't throw any errors. j is initialized in it's original declaration to 0. Just in case, I set it to 0 just before the string tokenization. After running I got a trap at the same point.

I don't think this is part of the problem.

I'm pretty sure it's ok, but is there something wrong with my gets() statement? admittedly my C is a bit rusty and maybe I'm taking something for granted since I've been doing more java lately, but in comparing these to examples on google there's no problems....
Was This Post Helpful? 0
  • +
  • -

#19 jimblumberg   User is offline

  • member icon

Reputation: 5916
  • View blog
  • Posts: 17,932
  • Joined: 25-December 09

Re: searching for a file, writing to a different file and Unix.

Posted 24 October 2011 - 04:40 PM

I don't see where you have initialized this variable anywhere. The following code doe not initialize anything except m.
		int i, j, k, l, m =0;


After I initialize this variable the program runs to conclusion.

Show your code where you initialize this variable.

Jim
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2