473,406 Members | 2,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

type mismatch in redeclaration of remove

6
Expand|Select|Wrap|Line Numbers
  1.  
  2. #include<stdio.h>
  3. int remove(char s[]);
  4. int getline(char line[],int len);
  5.  
  6. main()
  7. {
  8.     int len;
  9.     len=0;
  10.      char line[100];
  11.     while(getline(line,len)>0)
  12.         if(remove(line)>0)
  13.        printf("%s",line);
  14. }
  15.  
  16. int remove(char s[])
  17. {
  18.      int i;
  19.       i=0;
  20.      while(s[i]!='\n')
  21.        ++i;
  22.    return i;
  23. }
  24.  
this is my half program...i have just started programming in c...m getting an error that type mismatch in redeclaration of remove...can some one help me in rectifying the error..
Sep 6 '11 #1

✓ answered by Banfa

remove is a C standard library function declared in stdio.h as

int remove ( const char * filename );


You should use a different name for this function in your code. Presumably you got the error at line 3. Since this is your first line of code that should have been an indication that it was something to do with the stdio.h header.

You need to learn what is in the standard library so you can avoid these conflicts.

7 10676
alexis4
113 100+
Where is the getline() function?
Sep 6 '11 #2
alexis4
113 100+
I wrote a dummy getline() function and compiled just fine with my compiler. It seems that this way of function call is not supported by your compiler.

I then compiled it with strict ISO/ANSI and got an error at line 9:

Error[Pe268]: declaration may not appear after executable statement in block
Which means that you have to change line 8 and 9 between them because a declaration is forbidden after executable code. But you are saying that you are getting another error.

Just googled it:

Check out this link here, it tells you clearly what to do:
Sep 6 '11 #3
Banfa
9,065 Expert Mod 8TB
remove is a C standard library function declared in stdio.h as

int remove ( const char * filename );


You should use a different name for this function in your code. Presumably you got the error at line 3. Since this is your first line of code that should have been an indication that it was something to do with the stdio.h header.

You need to learn what is in the standard library so you can avoid these conflicts.
Sep 7 '11 #4
tan007
6
my getline function takes input from the user...no problem in that....
and i have used name remove in many other prog..just works fine...
my whole prog is correct and even my function prototype and definition...i have used the same function in other program it works fine..only in this program its giving me an error...
Sep 7 '11 #5
tan007
6
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #define MAXLINE 100
  3. /*exercise 1.18 */
  4. int getline(char line[],int maxline);
  5. int remove(char s[]);
  6.  
  7. /*print longest line input*/
  8. main()
  9. {
  10.     int r;
  11.     int len;  /*current line length*/
  12.     int max;  /*maximum length seen so far*/
  13.     char line[MAXLINE];
  14.     char longest[MAXLINE];
  15.  
  16.     max=0;
  17.     while((len = getline(line,MAXLINE)) >0)
  18.       {
  19.               r=remove(line);
  20.               if(r>0)
  21.                printf("%s",line);
  22.      }
  23.     return 0;
  24. }
  25.  
  26. /*getline:read a line into s,return length*/
  27. int getline(char s[],int lim)
  28. {
  29.     int c,i,j;
  30.     j=0;
  31.     for(i=0; (c=getchar())!=EOF && c!='\n';++i)
  32.         if(i<lim-2)
  33.         {
  34.         s[j]=c;
  35.         ++j;
  36.         }
  37.         if(c=='\n')
  38.         {
  39.             s[j]=c;
  40.             ++j;
  41.             ++i;
  42.          }
  43.     s[j]='\0';
  44.     return i;
  45. }
  46.  
  47. /*remove the tabs and blanks*/
  48. int  remove(char s[])
  49. {
  50.     int i;
  51.     i=0;
  52.     while(s[i]!='\n')
  53.         ++i;
  54.     --i;
  55.     while(i>=0 && (s[i]==' ' || s[i]=='\t'))
  56.         --i;
  57.      if(i>=0){
  58.         ++i;
  59.         s[i]='\n';
  60.         ++i;
  61.         s[i]='\0';
  62.         }
  63.  
  64.       return i;
  65. }

this is my entire program....plz check if u can find any error....m getting an error....type mismatch in declaration of remove
Sep 7 '11 #6
Banfa
9,065 Expert Mod 8TB
I'm not all that worried about what you have done previously, here you are getting a type mismatch because you have declared remove differently to how it is declared in stdio.h.

I suggest you get out of the habit of using the name remove for your own functions since it is a standard library function. At some point (when one of your programs needs to call standard library remove) this is going to trip you up and cause very unexpected results.
Sep 8 '11 #7
tan007
6
thnks banfa.....my error got solved....
Sep 10 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Arun Wadhawan | last post by:
Hello MY SQL Server is causing me this problem : Microsoft VBScript runtime error '800a000d' Type mismatch: 'ident' >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> I am getting from...
1
by: LJgrnl | last post by:
I've got a type mismatch error that's driving me nutty. Variable blnNoData has the initial value False. If a recordset comes back empty (both .EOF and ..BOF are true) then blnNoData is set to...
1
by: Mark | last post by:
Hi - I tried this in VS.Net, and also in the Web Matrix code below: - but I am getting a type mismatch error. The sql statement runs perfectly from within the Access Query Designer. Can anyone...
7
by: middletree | last post by:
I've been messing with this for hours, and have been to various sites, including Aaron's site, and am truly stumped. The short version: in SQL Server, the 4 fields in question are datetime. I...
4
by: Mike | last post by:
I am getting a type mismatch error when I do a bulk insert. ---Begin Error Msg--- Server: Msg 4864, Level 16, State 1, Line 1 Bulk insert data conversion error (type mismatch) for row 1, column...
3
by: amitbadgi | last post by:
I am getting teh following error while converting an asp application to asp.net, Exception Details: System.Runtime.InteropServices.COMException: Type mismatch. Source Error: Line...
1
by: Brett | last post by:
I have a form that calls a method within a DLL. By clicking a button on the form, the DLL is instantiated and the SaveOutlookMessage() method invoked. The DLL code copies messages from Outlook to...
6
by: Howard Kaikow | last post by:
I'm doing a VB 6 project in which I am trying to protect against type mismatch errors. Is the process any different in VB .NET? Here's what I'm doing in VB 6. I have an ActiveX DLL. The...
19
by: Lysander | last post by:
I have written a query that takes three integers representing day,month and year, forms a date from them and compares this date to the date the record was entered and returns any records where the...
1
by: crookward | last post by:
I usually have no problem identifying a type mismatch error, but this one's got me pulling my hair out. The mismatch error is pointing to line 269, which is a blank line, and it's also within an if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.