I'm having this error but I don't know why it's happening, here it is:
Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "void __cdecl sdds::comPhone(struct sdds::Phone * const,char * const,int)" (?comPhone@sdds@@YAXQEAUPhone@1@QEADH@Z) referenced in function "void __cdecl sdds::phoneDir(char const *,char const *)" (?phoneDir@sdds@@YAXPEBD0@Z) DIY C:\Users\iv4n3\Desktop\Sem 2\OOP244\Workshops\WS01\DIY\Phone.obj
The code is here:
main.cpp
#define _CRT_SECURE_NO_WARNINGS
#include "Phone.h"
using namespace sdds;
int main()
{
phoneDir("Star Wars", "phones.txt");
return 0;
}
Phone.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include "cStrTools.h"
#include "Phone.h"
using namespace std;
namespace sdds
{
void phoneDir(const char* str1, const char* str2)
{
char flag[30];
int count = 0;
Phone phone[MAX_CONTACTS] = { {0} };
FILE* fp;
fp = fopen(str2, "r");
if (!fp)
{
cout << str2 << " file not found!" << endl;
}
else
{
while (fscanf(fp, "%[^\t]\t%s\t%s\t%s\n", phone[count].name, phone[count].area, phone[count].prefix, phone[count].number) != EOF && count < MAX_CONTACTS)
{
count++;
}
while (!(flag == "!"))
{
cout << str1 << " phone direcotry search" << endl;
cout << "-------------------------------------------------------" << endl;
cout << "Enter a partial name to search (no spaces) or enter '!' to exit" << endl;
cin >> flag;
comPhone(phone, flag, count);
cin.clear();
}
}
cout << "Thank you for using Star Wars directory.";
}
void comPhone(const Phone phone[], const char flag[], int count)
{
int i = 0;
int j = 0;
char str1[30];
char str2[30];
while (j < strLen(str1))
{
str1[j] = toLower(flag[j]);
j++;
}
while (i < count)
{
j = 0;
while (j < strLen(str2))
{
str1[j] = toLower(flag[j]);
j++;
}
if (strnCmp(str1, str2, strLen(flag)))
{
cout << phone[i].name << ": (" << phone[i].area << ") " << phone[i].prefix << "-" << phone[i].number << endl;
}
i++;
}
}
}
Phone.h
#pragma once
#ifndef _PHONE_H
#define _PHONE_H
#define MAX_CONTACTS 30
namespace sdds
{
struct Phone
{
char name[20];
char area[10];
char prefix[10];
char number[10];
};
void phoneDir(const char* str1, const char* str2);
void comPhone(Phone phone[], char flag[], int count);
}
#endif
cStrTools.cpp
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <iomanip>
#include "cStrTools.h"
namespace sdds
{
char toLower(char ch)
{
if (ch >= 'A' && ch <= 'Z') ch += ('a' - 'A');
return ch;
}
int strCmp(const char* s1, const char* s2)
{
int i;
for (i = 0; s1[i] && s2[i] && s1[i] == s2[i]; i++);
return s1[i] - s2[i];
}
int strnCmp(const char* s1, const char* s2, int len)
{
int i = 0;
while (i < len - 1 && s1[i] && s2[i] && s1[i] == s2[i]) {
i++;
}
return s1[i] - s2[i];
}
void strCpy(char* des, const char* src)
{
int i;
for (i = 0; src[i]; i++) des[i] = src[i];
des[i] = 0;
}
int strLen(const char* str)
{
int len;
for (len = 0; str[len]; len++);
return len;
}
const char* strStr(const char* str, const char* find)
{
const char* faddress = nullptr;
int i, flen = strLen(find), slen = strLen(str);
for (i = 0; i <= slen - flen && strnCmp(&str[i], find, flen); i++);
if (i <= slen - flen) faddress = &str[i];
return faddress;
}
int isAlpha(char ch)
{
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
}
int isSpace(char ch)
{
return ch == ' ' || ch == '\t' || ch == '\n' || ch == '\v' || ch == '\f' || ch == '\r';
}
void trim(char word[])
{
int i;
while (word[0] && !isAlpha(word[0])) {
strCpy(word, word + 1);
}
i = strLen(word);
while (i && !isAlpha(word[i - 1]))
{
word[i-- - 1] = 0;
}
}
void toLowerCaseAndCopy(char des[], const char source[])
{
int i = 0, j = 0;
for (; source[i] != 0; i++) {
des[j++] = toLower(source[i]);
}
des[j] = 0;
}
}
cStrTools.h
#pragma once
#ifndef _CSTRTOOLS_H
#define _CSTRTOOLS_H
namespace sdds
{
char toLower(char ch);
int strCmp(const char* s1, const char* s2);
int strnCmp(const char* s1, const char* s2, int len);
void strCpy(char* des, const char* src);
int strLen(const char* str);
const char* strStr(const char* str, const char* find);
int isAlpha(char ch);
const char* strStr(const char* str, const char* find);
int isAlpha(char ch);
int isSpace(char ch);
void trim(char word[]);
void toLowerCaseAndCopy(char des[], const char source[]);
}
#endif