-
September 19th, 2010, 12:26 AM
#1
Printing a String
I am trying to print the contents of a buffer LPMIDIHDR lpBuffer
I am after the lpData member, and since it is declared as LPSTR
I tried doing it this way:
Code:
fprintf(fp,"lpBuffer = <%s>\n", &lpBuffer[i].lpData);
But I am only getting one character
lpBuffer = <H>
What do I have to do to print out the entire string?
This is the structure from MSDN
Code:
typedef struct midihdr_tag {
LPSTR lpData;
DWORD dwBufferLength;
DWORD dwBytesRecorded;
DWORD_PTR dwUser;
DWORD dwFlags;
struct midihdr_tag *lpNext;
DWORD_PTR reserved;
DWORD dwOffset;
DWORD_PTR dwReserved[4];
} MIDIHDR, *LPMIDIHDR;
-
September 19th, 2010, 03:17 AM
#2
Re: Printing a String
Try it without the "&" in front of lpBuffer[i].lpData, as "&lpBuffer[i].lpData" would be the address of the string pointer, not the address of the string.
-
September 19th, 2010, 08:13 AM
#3
Re: Printing a String
Thanks for offering some help.
Still not getting the results I expect.
fprintf(fp, "[%d] <%s>\n", j, lpBuffer[0].lpData);
returns
[0] <>
[1] <>
[2] <>
[3] <>
[4] <>
[5] <>
[6] <>
[7] <>
[8] <>
[9] <>
[10] <>
[11] <>
[12] <>
.
.
.
fprintf(fp, "[%d] <%s>\n", j, &lpBuffer[0].lpData[j]);
returns
[0] <>
[1] <>
[2] <>
[3] <>
[4] <>
[5] <>
[6] <>
[7] <>
[8] <ÀÔ>
[9] <Ô>
[10] <>
[11] <>
[12] <>
.
.
.
fprintf(fp, "[%d] <%s>\n", j, lpBuffer[0].lpData[j]);
returns
Unhandled exception error
-
September 19th, 2010, 09:28 AM
#4
Re: Printing a String
Changing the specifier in fprintf works with your suggestion... Thanks!
Code:
FILE *fp2;
fp2 = fopen("output2.txt", "w");
fprintf(fp2, "dwBytesRecorded = %d\n", lpBuffer[0].dwBytesRecorded);
for (j = 0; j < (lpBuffer[0].dwBytesRecorded); j++) {
fprintf(fp2, "[%d] <%x\n", j, lpBuffer[0].lpData[j]);
}
fclose(fp2);
returns
dwBytesRecorded = 348
[0] <0>
[1] <0>
[2] <0>
[3] <0>
[4] <0>
[5] <0>
[6] <0>
[7] <0>
[8] <ffffffc0>
[9] <ffffffd4>
[10] <1>
[11] <1>
[12] <0>
.
.
.
-
September 20th, 2010, 11:07 AM
#5
Re: Printing a String
Originally Posted by mmscg
Changing the specifier in fprintf works with your suggestion... Thanks!
Code:
FILE *fp2;
fp2 = fopen("output2.txt", "w");
fprintf(fp2, "dwBytesRecorded = %d\n", lpBuffer[0].dwBytesRecorded);
for (j = 0; j < (lpBuffer[0].dwBytesRecorded); j++) {
fprintf(fp2, "[%d] <%x\n", j, lpBuffer[0].lpData[j]);
}
fclose(fp2);
returns
dwBytesRecorded = 348
[0] <0>
[1] <0>
[2] <0>
[3] <0>
[4] <0>
[5] <0>
[6] <0>
[7] <0>
[8] <ffffffc0>
[9] <ffffffd4>
[10] <1>
[11] <1>
[12] <0>
.
.
.
Yep, because lpData is not a string, it's the MIDI data:
http://msdn.microsoft.com/en-us/libr...=VS.85%29.aspx
Viggy
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|