Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

having problem with strputc and strgetc

Status
Not open for further replies.

dbsquared

Programmer
Nov 7, 2002
175
US
here is the problem that I am having. I have to log into a sun server and pull IP addresses for certain peices of equipment that are connetcted to that equipment. I then have to log into each peice of equipmetn to pull data from it. I would just create a static IP list but these IP's can and will be added to. Another issue is that each sun server is formatted a little differently so I did a capture for each sun server and am trying to recover the IP's from the capture file. I ahve the code to get to the appropriate line in the file and test it and when I get the first and last number number of the IP.

Here is the problem that I am having: I am using strgetc from the gets from the file and put that number into another variable then store it into an array so that I can do a group of logins at one time. When I am testing to see what is being stored in the first variable I notice that I am getting errorneous data apparently from memory in the variable at the same time that I am puting in the IP address numbers. I have tried renaming variables and I clear the variable right before I enter into the while func to use the strgetc and strputc. Any help would be appreciated.

Here is a snippet fo the code:

if fopen 0 file_name Read
statmsg "file %s is open", file_name

while not feof 0 fgets 0 File_Info
if strfind File_Info "EDGERTR"
if second >0 ;have to loop to second time it sees this toget the first IP
Imhere = 0
while Chr!=47
strgetc File_Info Pos Chr
if Chr==49 ;make sure have a 1
Tempstr = ""
while Chr != 47 ;character after last number is /
strputc Tempstr Imhere Chr
usermsg "RPM IP is %s", Tempstr
Pos++
Imhere++
strgetc File_Info Pos Chr
endwhile
endwhile
RPMIP[getnum] = Tempstr
usermsg "RPMIP array: %s", RPMIP[getnum]
endif
Pos++
endwhile
endif
if strcmp RPM_IP ""
else
getnum++
endif
second ++

endif

To go where no programmer has gone before.
 
Can you post some sample data from the file you are reading? I think using the strtok command to "break apart" a string you've read from the file will be easier than manually reading character by character.

I would also recommend adding the TEXT argument to the fopen command so that any trailing carriage returns and linefeeds are not in the string you are parsing.


aspect@aspectscripting.com
 
the data I am getting in the variable is not from the file.
when I use the user message user message appears in the variable.

here is an example of data from the file:

AN-10 EDGERTR-10-2 11.207.128.13/ RPM7200
255.255.255.252


I get a lot of garbage in the variable that seems to be randomly coming form memory.

To go where no programmer has gone before.
 
ex data below:
AN-10 EDGERTR-10-2 11.207.128.13/ RPM7200
255.255.255.252


If the data format is always the same as this I would use strextract statements:

integer dlm_num
...
strextract Tempstr File_info "/" 0 ; ex. tempstr =" AN-10 EDGERTR-10-2 11.207.128.13"
strsearch tempstr " " dlm_num
strextract RPMIP[getnum] " " dlm_num ; ex. RPMIP[getnum]="11.207.128.13"


With a little bit of creativity you can usually get the right data out of a source string with just a few commands using strextract and strsearch commands even if the data varies a little from occurrence to occurrence.

Hope this helps. DT
 
I left the Tempstr srouce string for the strextract off the second strextract command by accident.

So I put it in and moved the comments to the lines below what they apply to.


integer dlm_num
...
strextract Tempstr File_info "/" 0
; ex. tempstr =" AN-10 EDGERTR-10-2 11.207.128.13"
strsearch tempstr " " dlm_num
; dlm_str will have the number of spaces in the string before the IP addr
strextract RPMIP[getnum] Tempstr " " dlm_num
; ex. RPMIP[getnum]="11.207.128.13"


The strextract command works:

strextract Var_trgt_dat_str Srce_str Dlmtr_str Instnc_int

Returns the a string from the source string that is between the instance Instc_int and Instc_int + 1 (or null char) of the Dlmtr_str within the Srce_str into the variable Var_trgt_dat_str.

Var_trgt_dat_str - A string variable to receive the output string of characters.
Srce_str - A string to be parsed by a known delimiter character(s).
Dlmtr_str - Character(s) known to separate a portion of the source string.
Instnc_int - A zero-based integer specifying after which occurrence of the delimiter string to take the characters from up to the next occurrence or the end of string (next null character) to return.
If Instnc_int is 0 it will take from the start of the source string up to the first occurrence of the delimiter string.


Sorry about the missing parameter in the previous post.

Again hope this helps. DT
 
Thanks DT I will try it today if I get a chance.

To go where no programmer has gone before.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top