I am trying to send the contents of a plist file over a socket. userPlist
is a ifstream
and the file opens correctly and as it should. But when it is run it only sends bplist00?
over the socket and then stops. Why would that be? Here is my source code:
if (userPlist.is_open()) {
string line;
int i;
int sizeOfPlist;
char plistChar[128];
while (getline(userPlist, line)) {
sizeOfPlist = line.size();
for (i = 0; i <= sizeOfPlist; i++)
{
plistChar[i] = line[i];
}
line = "\0";
send(sock, plistChar, strlen(plistChar), 0);
for (i = 0; i < 128; i++) {
plistChar[i] = '\0';
}
send(sock, "\n", strlen("\n"), 0);
}
}
If anybody has any suggestions or advice, that would be great. Thanks.
Suggestion: If your file stops reading after the first line then my guess is that it is an issue with your while loop - have you checked to see if the while loop is executing more than once? Use breakpoints in the debugger to do this. I don't think getline() is a valid conditional check but it's worth checking