I am completely new to c++ and I am tyring to build my programm but i get the error C2109: subscript requires array or pointer type on lines 136 and 230 .Please can someone help me :)
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
}
fin.close();
}
else
cerr << "unable to open file QUOTES.txt" << endl;
}
void InsertLine() //DO InsertLine
{
char BufferArray[NLINES][HSIZE]={0}; // INITIALISE BufferArray 25 by 50 with 0
int iAfter=0; // INITIALISE iAfter with 0
int iCounter=0;
cout << "After which line would you like to insert? "; // PROMPT "After which line would you like to insert? "
cin >> iAfter; // INPUT into iAfter
fflush(stdin); //Removes any rememberence from the stream buffer - only required in windows environment
for(iCounter = iAfter; iCounter < NLINES; iCounter++) // FOR iCounter from iAfter to NLINES
{ // LOOP
strcpy(BufferArray[iCounter+1], szLineNames[iCounter]); // COPY szLineNames[iCounter] to BufferArray[iCounter]
} // END LOOP
cout << "Please enter another line name: "; // PROMPT "Please enter another line name: "
cin.getline (szLineNames[iAfter],sizeof(szLineNames[iAfter])); // INPUT into szLineNames[iAfter+1]
for(iCounter = iAfter+1; iCounter < NLINES; iCounter++) // FOR iCounter from iAfter to NLINES-1
{ // LOOP
strcpy(szLineNames[iCounter],BufferArray[iCounter]); // COPY BufferArray[iCounter] to szLineNames[iCounter+1]
} // END LOOP
} //END DO InsertLine
void SwapTwoLines() //DOSwapTwoLines
{
int iLineNumber1=0, iLineNumber2=0; //SET LineNumber1to 0 , LineNumber2 to 0, Buffer to 0
char szBuffer[HSIZE]={0};
cout << "Please input the two line numbers to be swapped:"; //PROMPT "Please input the two line numbers to be swapped:"
void DeleteLine() // Do Delete line
{
int iLineNumber = 0; // INITIALISE iLineNumber with 0
cout << "Please enter a line number you would like to delete "; // PROMPT "Please enter a line number you would like to delete "
cin >> iLineNumber; // INPUT into iLineNumber
strcpy(szLineNames[iLineNumber-1],""); // COPY "" to szLineNames
}
void RenameLine() //DO RenameLine
{
char szToBeReplaced[HSIZE] = {0}; //INITIALISE szToBeReplaced with 0
char szReplacement[HSIZE] = {0}; //INITIALISE szReplacement with 0
int i=0;
int iTargetLine = 0;
int iLength = 0; //INITIALISE i with 0 //INITIALISE iTargetLine with 0
char * pszPosition = 0; //INITIALISE Position with 0
char szRemainder [HSIZE] = {0}; //INITIALISE Remainder with 0
cout << "Please enter a name to be changed"; // PROMPT "Please enter a name to be changed"
cin.getline(szToBeReplaced,sizeof(szToBeReplaced)); // INPUT into szToBeReplaced
cout << "Please enter the new name"; // PROMPT "Please enter the new name"
cin.getline(szReplacement,sizeof(szReplacement)); // INPUT into szReplacement
for (i=0; i<NLINES;i++) //FOR I from 0 to NLINES
{ //LOOP
if(pszPosition = strstr(szLineNames[i],szToBeReplaced)) // IF szToBeReplaced is found in szLineNames[i]
{ //THEN
// SAVE the position of szToBeReplaced within szLineNames[i] as Position
iTargetLine = i; // COPY I to iTargetLine (first occurrence of)
break; // EXIT from the loop
} //END IF
}
//ENDLOOP
iLength = strlen(szToBeReplaced); //CALCULATE the length of szToBeReplaced
//SAVE it to iLength
strcpy(szRemainder, pszPosition+iLength); //COPY Position+iLength to szRemainder
strcpy(pszPosition, szReplacement); //COPY szReplacement to Position
strcat(szLineNames[iTargetLine], szRemainder); //CONCATENATE szRemainder to szLineNames[iTargetLine]
can you just post the codes around those lines? Or just the codes where you think problem may lie? nobody will look through this...you have not even used the code tags to format your post.
This is getting SERIOUSLY annoying, 90% of new posts don't use the [ code ] tags and it's impossible to read. Edit your post and use [ code ] and [/code] tags at the start and end of your code so that it's readable. Otherwise no one is going to take the time to look through that sloppy unindented code.
You say use code tags, its not like I am doing this on purpose, I have explained that I am new, I was advised to use this forum for help and advise as I am a complete beginner, all I wanted was help. I cannot help being new can I, the whole reason I am on here is to get better.
Just a tip: You included <string> but didn't actually use the string type. I think using it could make life easier for you.
Also, I think the problem is with Register. I only see you initialized it with char Register [NLINES] = {0}; and accessed it in your functions (where do you fill it with something you can actually read?).
I understand that hb84 but I asked you to use code tags and you replied with more code and no code tags. Also you have to understand that people come to this message board on their free time to help others (and get help) and CONSTANTLY every day people are making new posts without using code tags.
It is very, VERY hard to read code like that and if these new guys would just read 2-3 posts before asking for help they would see that it's necessary to use code tags when requesting help. I didn't use all caps because I was mad, I just said it before and you obviously didn't notice so I wanted to be more clear. (;