Error executing link.exe??

S

surlogics

The function of the program is to output the longest word in a
sentence.

#include<stdio.H>
#include<string.H>
main()
{int alphabetic(char);
int longest(char []);
int i;
char line[100];
printf("input one line");
gets(line);
printf("the longest word is:");
for(i=longest(line);alphabetic(line);i++)
printf("%c",line);
}

int alphabetic(char c)
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
return(1);
else
return(0);
}

int longest(char string[])
{int alphabetic(char c);
int i,length=0,len=0,place,inaword=0; /*inaword=0 refers to the
"cursor" is not in a word*/
for(i=0;i<=strlen(string);i++)
{if(alpabetic(string))
{inaword=1;
place=i;
len++;}
else
{inaword=0;
if(length<len)
{length=len;
place=i;
len=0;
}
}
}
return(place);
}


But when i try to link(visual c++6), it said
"Linking...
c.obj : error LNK2001: unresolved external symbol _alpabetic
Debug/c.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe."

I don't understand why.Can anyone help me? Thx!
 
R

raashid bhatt

The function of the program is to output the longest word in a
sentence.

#include<stdio.H>
#include<string.H>
main()
{int alphabetic(char);
 int longest(char []);
 int i;
 char line[100];
 printf("input one line");
 gets(line);
 printf("the longest word is:");
 for(i=longest(line);alphabetic(line);i++)
         printf("%c",line);

}


what are u doing man function prototype inside another function?
int alphabetic(char);
int longest(char []);

take them outside main

and append __cdecl before fucntion name
Thanks!!
 
M

Martin Ambuhl

(e-mail address removed) wrote:

Here's the declaration:
{int alphabetic(char);

And the error message:
"Linking...
c.obj : error LNK2001: unresolved external symbol _alpabetic
I don't understand why.Can anyone help me? Thx!

I'm not "Thx", but even I can notice that "alpabetic" and "alphabetic"
are not the same.
 
M

Martin Ambuhl

raashid said:
what are u doing man function prototype inside another function?
int alphabetic(char);
int longest(char []);

There is nothing wrong with having a declaration inside another
function. If that fellow with the short name "u" can do it.
take them outside main

There is no need.
and append __cdecl before fucntion name

There is nothing in the C programming language named "__cdecl" and, even
if there were, it has nothing to do with his problem, which was simply
misspelling his identifier.
 
I

Ian Collins

The function of the program is to output the longest word in a
sentence.

#include<stdio.H>
#include<string.H>

These shouldn't have a capital H.

That should be int main(void)
{int alphabetic(char);
int longest(char []);
int i;
char line[100];
printf("input one line");
gets(line);

Never, ever use gets. Use fgets(line, 100, stdin) and change 100 to a
named constant.
printf("the longest word is:");
for(i=longest(line);alphabetic(line);i++)
printf("%c",line);
}

int alphabetic(char c)
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
return(1);
else
return(0);
}

int longest(char string[])
{int alphabetic(char c);
int i,length=0,len=0,place,inaword=0; /*inaword=0 refers to the
"cursor" is not in a word*/
for(i=0;i<=strlen(string);i++)
{if(alpabetic(string))


You spelt alphabetic wrong here.
 
I

Ian Collins

raashid said:
what are u doing man function prototype inside another function?
int alphabetic(char);
int longest(char []);
There's nothing wrong with putting function prototypes in a function body.
take them outside main

and append __cdecl before fucntion name

Why on Earth would anyone do that?
 
A

Andrew Poelstra

The function of the program is to output the longest word in a
sentence.

Well, you've got a number of problems (I won't mention stylistic
concerns, but suffice to say this code is very hard to read):
#include<stdio.H>
#include<string.H>

These should be .h, not .H.

int main(void)
{int alphabetic(char);
int longest(char []);
int i;
char line[100];
printf("input one line");
gets(line);

*Never* use gets(). It is bug unto itself. Instead try
fgets(line, sizeof line, stdin);
printf("the longest word is:");
for(i=longest(line);alphabetic(line);i++)


There is a standard C function (macro?) isalpha() you could use instead
of alphabetic().
printf("%c",line);


Another standard C function, putc(), will do this for you.
}

int alphabetic(char c)
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))
return(1);
else
return(0);
}

There's no guarantee that this will work: what if you are using a
character set where letters are not consecutive? Use isalpha() instead.
int longest(char string[])
{int alphabetic(char c);

Consider giving function prototypes file scope, and moving them to
shared header files. This makes them easier to update.
int i,length=0,len=0,place,inaword=0; /*inaword=0 refers to the
"cursor" is not in a word*/
for(i=0;i<=strlen(string);i++)
{if(alpabetic(string))


Here is your reported error. You spelt alphabetic() wrong.
{inaword=1;
place=i;
len++;}
else
{inaword=0;
if(length<len)
{length=len;
place=i;
len=0;
}
}
}
return(place);
}

Yikes! Consider using pointers instead to make this function
more concise. You could do it with three local variables, as
opposed to the 6 you are using now.
 
B

Barry Schwarz

The function of the program is to output the longest word in a
sentence.

#include<stdio.H>

C is case sensitive. The correct header is stdio.h.
#include<string.H>
main()
{int alphabetic(char);
int longest(char []);
int i;
char line[100];
printf("input one line");
gets(line);
printf("the longest word is:");
for(i=longest(line);alphabetic(line);i++)


Horizontal white space is not completely cost free but it is a very
cheap way to improve the readability of your code. At a minimum, add
a space after each semicolon.
printf("%c",line);
}

int alphabetic(char c)


This entire function is unnecessary as there is already a standard C
function to do this.
{if((c>='a'&&c<='z')||(c>='A'&&c<='Z'))

This test is valid in ASCII. However, it yields incorrect results in
EBCDIC.
return(1);

return is a statement, not a function. The parentheses are allowed
but unnecessary.
else
return(0);
}

int longest(char string[])

The name string is reserved for the implementation. It would benefit
you not to use names starting with "str".
{int alphabetic(char c);

If you would place your prototypes at file scope at the beginning of
your source, you would not have to repeat them.
int i,length=0,len=0,place,inaword=0; /*inaword=0 refers to the
"cursor" is not in a word*/
for(i=0;i<=strlen(string);i++)
{if(alpabetic(string))


Maybe your keyboard has a problem with the character "h". Here it is
missing.
{inaword=1;
place=i;

You only want to do this if this is the very first character in the
word. Otherwise place will end up as the index of the last character
in the word.
len++;}
else
{inaword=0;
if(length<len)
{length=len;
place=i;

I'm pretty sure you don't want this line here at all. This will cause
place to be the index of the character one byte beyond the end of the
word.
 
J

Joachim Schmitz

Barry said:
C is case sensitive. The correct header is stdio.h.

The filesystem might notbe case sensitive...
one platform I konw of doesn't use the '.' to separate filename from
extension so #include <stdioh> does work too, as does #include <StdIoH>, as
that system isn't case sensiteve either.

no reason though to not use the correct stdio.h of course.


Bye, Jojo
 
A

Andrew Poelstra

The filesystem might notbe case sensitive...

That doesn't necessarily have anything to do with stdio.h. The C
Standard does not require headers to be actual files, though they
commonly are.
 
K

Keith Thompson

Barry Schwarz said:
C is case sensitive. The correct header is stdio.h.
[...]

Essentially correct, but ...

The interpretation of header names, including whether they're
case-sensitive or not, is implementation-defined.

"#include <stdio.h>" is certainly the correct form, and
"#include <stdio.H>" should be avoided. My point is that the latter
won't necessarily be flagged as an error (it's likely to be accepted
on Windows, for example).
 
A

Andrew Poelstra

int longest(char string[])

The name string is reserved for the implementation. It would benefit
you not to use names starting with "str".

In this case, he could use String with a capital S. (Note that for
external variables this is not generally true since linkers are not
required to be case-sensitive).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top