Yes, function questions

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
void tableinsert(string DN, string IP, string DNarray[], string IParray[], int size) //function that places the data into a table 
{
	DNindex = searchTable(DNarray[], DN, size);
	if(DNindex!= -1)
	{
		IParray[DNindex] = IP;
	}
	else
	{
		//put into the array
		size++;

}
int searchTable(string array[], string FindMe, int size) 
{
	for(int t = 0; t < size; t++)
	{
		if(array[i] == FindMe)
		{
			return t;
		}
	}
	return -1;

}


I have a series of questions:

1.) It tells me that several items are undeclared when I was assuming that they were givens when working with array (DNindex, [i])
2.) How would you go about putting the items into the arrays?

These are set up to be like DNS address, IP addresses, and whether or not they are in either array for them and if they should be put into the arrays.

such as:

= www.google.com 1.2.3.4 //would put the data into the table
? 1.2.3.4 //would check if 1.2.3.4 is in an array.
What do you mean "given"?
DNindex is undeclared. What is it supposed to be?
i is also undeclared. Why are you using i as a subindex when you have t?
Like I assumed that the index of something was given as to be the contents fo the array.

is DNindex supposed to be an int? like, -1 is an int value. hmmm

and as for i I have no clue. int as well?
DNindex, i see, is supposed to be an integer value because it is coming from a previous int function. Alright, cool. but what about [i] in line 18?

And why a syntax error on line 3?
Like I assumed that the index of something was given as to be the contents fo the array.
The fact that arrays have elements and an index can be used to access them doesn't mean that declaring an array magically creates a variable with "index" appended to its name. (Not to mention that DN is not an array.)

is DNindex supposed to be an int?
You don't know? How did you know you needed the variable without knowing what type it should be?
DNindex should be of the same type that returns searchTable().

and as for i I have no clue. int as well?
What I asked was, why are you using 'i' as an index when you're using 't' as the for loop index? Why don't you use t, instead?
Or change t into i, whatever.


Are you coding in a state of trance? :-)

What I asked was, why are you using 'i' as an index when you're using 't' as the for loop index? Why don't you use t, instead?
Or change t into i, whatever.


I see! Wow! Okay okay, let me get back on track here and get back to you.


Are you coding in a state of trance? :-)


Haha, yes, just a little.
if you guys wouldn't mind helping me again, it would be much appreciated

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <iostream> //needed for cout and cin
#include <fstream> // needed for opening, reading, and closing a file.
#include <string> // needed for processing string data types


using namespace std; //not really sure what this does, but I always use it

void tableinsert(string DN, string IP, string DNarray[], string IParray[], int size); //prototype for tableinsert function
int searchTable(string array[], string FindMe, int& size); //prototype for the searchTable function.

int main() //main function
{
	const int SIZE = 10; //setting a constant value for the arrays,just in case it ever needs changing
	string file_Name; //what the file shall be none as when read in
	ifstream InFile; //used for bringing stuff in from the file
	ofstream OuFile; //used for bringing stuff out. Might be deleted if not used.
	char symbol; //where it stores the "=" and "?"
	string DNS_Address[SIZE]; //array for storing the DNS addresses
	string IP_Address[SIZE]; //array for storing IP addresses
	int ctr = 0; //counter for ending the for loop.



	cout << "Please enter the name of the file to process: "; //nice message asking for the name of the file
	cin >> file_Name; //reading in the file name.

	InFile.open(file_Name.c_str()); //opening the file

	if(InFile.is_open() == false) //if the file doesn't exist, then it tells the user in a polite manner.
	{
		cout << "Sorry, there must be a mistake, there is no such file!" << endl; //polite message.
		return 1; //fail
	}
	
	InFile >> symbol; //reading in the first char "symbol"

	for(ctr = 0; ctr < SIZE; ctr++)
	{
		if(symbol == '=')
		{
			cout << "Proccessing " << symbol << endl;
			InFile >> DNS_Address[ctr];
			InFile >> IP_Address[ctr];
		}
		else
		{
			cout << "Processing " << symbol << endl;
			
		}
		InFile >> symbol;

		
		
	}
	

	

		
	

		

	
	


	return 0;
} // end of main function
void tableinsert(string DN, string IP, string DNarray[], string IParray[], int size) //function that places the data into a table 
{
	int DNindex = searchTable(DNarray, DN, size); //uses the searchTable function to returna value
	if(DNindex!= -1)
	{
		IParray[DNindex] = IP;
	}
	else
	{
		//put into the array
		size++;

}
}
int searchTable(string array[], string FindMe, int& size) 
{
	for(int t = 0; t < size; t++)
	{
		if(array[t] == FindMe)
		{
			return t;
		}
	}
	return -1;

}


My questions are as followed;
1.) How would I, in the tableInsert function, make sure it was placed in the correct array?
2.) When the symbol is not an = sign, how do I make it so that it only reads in the part that is there (IP Address or a DNS Address)?


the file is

= www.cs.uky.edu 1.2.3.4
= www.toyota.com 4.5.6.7
= ftp.uky.edu 3.4.5.1
= www.cs.uky.edu 5.6.7.8
? www.cs.uky.edu
? 1.2.3.4
? 3.4.5.1
= ftp.wust1.edu 128.92.38.8
? 128.92.38.8
? 5.6.7.8
Last edited on
Topic archived. No new replies allowed.