Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 23rd, 2006, 4:17 PM   #1
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
problem with a function

Hi I need to wirt a function in frtran77 that does the following:
integer function delete(id, list, n) where
• delete returns 0 if the deletion was successful, -1 if the list is empty, and -2 if the user is not currently in the list.
• id is the integer identification number of the user.
• list is the integer array from which the id is to be removed.
• n is the current length of the list.

I have wrote the code
  integer function delete(id,list,n)

        integer id,indexe,n,list(n)
        integer delete,nempty,idx,m

        delete=-100
        nempty=0           
      
        do 1000 idx=1,n      
        if (list(idx).EQ.101) then
          nempty=nempty+1
        end if
        
        if (list(idx) .EQ. id) then
           delete=0
           indexe=idx
                 do 30 m= indexe,n - 1  
                   list(m) = list(m+1) 
30               continue
                  n = n-1

        end if
      
 1000 continue
 
      if (delete .EQ. 0) then  
        return
      end if
      
      if (nempty .eq. n) then  
        delete=-1
        return
      end if
      
      delete=-2                
      return
      end

The way I call it in main is
integer p
.......
	else if(option.EQ.'DU') then
      write(6,*)'delete user',A
      p=delete(A,list,hh)
      write(6,*)'value of delete*',p
      
.................
when I remove the command in bolde it compile OK.

When I compile I have the following message
*** FUNCTION 'DELETE' returns a INTEGER(KIND=3) but has been called as if it returns a REAL(KIND=1) (from the main program)
I dont know why.
Please can someone help me please
B.
brad sue is offline   Reply With Quote
Old Apr 23rd, 2006, 4:41 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Please show your "main" function. If it's too large, zip and attach it.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 23rd, 2006, 7:36 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,209
Rep Power: 5 grumpy is on a distinguished road
Add a line "integer delete" to the set of declarations at the top of your main function. Optionally you might also wish to add a line "external delete" before that line. Essentially these are about telling the compiler that delete is a function that returns an integer (it will assume the function returns a REAL otherwise), which is what the error message is suggesting. The potential need for these does not change by simply having the function delete in the same source file.
grumpy is offline   Reply With Quote
Old Apr 23rd, 2006, 10:24 PM   #4
brad sue
Hobbyist Programmer
 
Join Date: Mar 2006
Posts: 115
Rep Power: 3 brad sue is on a distinguished road
yeah , the message is gone.
Thanks
brad sue is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:54 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC