|
So why not put a shortcut to your app in the Startup folder, rather than the app itself?
Shraddhan
|
|
|
|
|
How to read an ascii matrix from file?
The bigger problem is that I don't know the columns and rows number.
So I have to read the data (fscanf) but at the same time I have to catch the carriage-return (but fscanf can't help me!!)
Another question:
I have a function, for this, that works well but only with known matrix dimension;
it use fscanf and FILE object. Is possible to do the same using CFile and/or CString? (i.e. there is a cast from CFile to FILE?)
Thanks
Have a nice code day
|
|
|
|
|
well, don't use fscanf, read one line at a time, one "column" at a time.
I assume that you know the delimiter for each column, so use strtok to get each item for a line; add it to your matrix.
you could also pre-process your file, count the number of columns in the first line ( all lines have the same number of elements ? ) and count the number of lines in the file, then allocate your matrix with those numbers and re-read the file.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Thank you,
you gave me very good ideas
Have a nice code day
|
|
|
|
|
_Russell_ wrote: ...but at the same time I have to catch the carriage-return (but fscanf can't help me!!)
Sure it can. Why would you think otherwise?
_Russell_ wrote: Is possible to do the same using CFile and/or CString?
Certainly.
_Russell_ wrote: (i.e. there is a cast from CFile to FILE?)
Why bother using a CFile object then? In any case, no such conversion exists.
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Hi David,
DavidCrow wrote: Sure it can
let me understand: is there a way (using fscanf) to read a number from file and at the same time know if the CR is passed ?
Please, be more clear, and all my problems are solved.
Thanks for your help
Have a nice code day
|
|
|
|
|
_Russell_ wrote: is there a way (using fscanf) to read a number from file...
Yes.
int num;
FILE *pFile;
fscanf(pFile, "%d", &num);
_Russell_ wrote: ...and at the same time know if the CR is passed ?
What exactly do you mean by this? If you wish to read a line of text from a file, including the newline character, use fgets() .
"The words of God are not like the oak leaf which dies and falls to the earth, but like the pine tree which stays green forever." - Native American Proverb
|
|
|
|
|
Here's one way to do it with STL (I know you asked for MFC, sorry). It doesn't actually store anything but it shows the basic structure.
#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;
int main(int argc, char* argv[])
{
ifstream fs("C:\\a.txt");
string line;
while ( getline(fs, line) )
{
stringstream ss(line);
string word;
while ( ss >> word )
{
cout << word << " ***END OF WORD*** ";
}
cout << "***END OF LINE***" << endl;
}
return 0;
}
Nice and clean and it works on any system with a standard compliant C++ compiler.
Steve
|
|
|
|
|
Thank you friends
I solved it!
Have a nice code day
|
|
|
|
|
Does anybody know how to assign a TCHAR* fromo a LPTSTR.
This is my code:
p->shi502_netname ="test";<br />
LPTSTR h =p->shi502_netname ;<br />
TCHAR* var = h;<br />
<br />
cout<<var<<endl;
output: t
when I try to print out h i get the first letter of string pointed to by h;
I thing im no accessing the string from the pointer correctly
Kelvin Cikomo
|
|
|
|
|
kelprinc wrote: p->shi502_netname ="test";
_tcscpy(p->shi502_netname, _T("test"));
I think you should copy _T("test") to "p->shi502_netname".
Now it should work.
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
It did not work
I think i shld rephrase my question.
I want to access the string being pointed to by shi502_netname
i.e if i just type
cout<<p->shi502_netname<
|
|
|
|
|
kelprinc wrote:
TCHAR * shi502_netname = _T("test");
LPTSTR h = shi502_netname ;
TCHAR* var = h;
cout<<var<<endl;
< blockquote="">
Here this is printing fine.
What is this p->shi502_netname . Is this a pointer to a char or a single char .
Jesus Loves <marquee direction="up" height="40" scrolldelay="1" step="1" scrollamount="1" style="background:#aabbcc;border-bottom:thin solid 1px #6699cc">
--Owner Drawn
--Nothing special
--Defeat is temporary but surrender is permanent
--Never say quits
--Jesus is Lord
|
|
|
|
|
We are on totally different wave lengths.
Forget about the first part. Assume you have a struct p that has shi502_netname as its member. shi502_netname is of type LPTSTR.
now i want to print the LPTSTR string in the p struct.
I tried doing this p->shi502_netname, but all i get is the first letter of the string
Kelvin Chikomo
|
|
|
|
|
|
I have edited the struct, its not a normal struct (typedef)
typedef struct
{
LPTSTR shi502_netname;
}p;
p.shi502_netname = _T("test");
LPTSTR h = p.shi502_netname ;
TCHAR* var = h;cout<
|
|
|
|
|
|
Yes i do. you did not declare yours as *p look at my definition of my struct below
typedef struct
{
LPTSTR shi502_netname;
}*p;
p p1; //don't forget thisp1.shi502_netname = _T("test");LPTSTR h = p1.shi502_netname ;TCHAR* var = h;cout<
|
|
|
|
|
|
I tried it it did not work
the struct that iam using is part of the C++ libraries
here it is
typedef struct _SHARE_INFO_502 {
LPTSTR shi502_netname;
DWORD shi502_type;
LPTSTR shi502_remark;
DWORD shi502_permissions;
DWORD shi502_max_uses;
DWORD shi502_current_uses;
LPTSTR shi502_path;
LPTSTR shi502_passwd;
DWORD shi502_reserved;
PSECURITY_DESCRIPTOR shi502_security_descriptor;
} SHARE_INFO_502, *PSHARE_INFO_502, *LPSHARE_INFO_502;
And i have to use *PSHARE_INFO_502 as the name of the struct
Kelvin Chikomo
|
|
|
|
|
|
I get wrong out puts if i try this.
let me just give you part of my code
PSHARE_INFO_502 BufPtr,p;<br />
NET_API_STATUS res;<br />
LPTSTR lpszServer = NULL;<br />
DWORD er=0,tr=0,resume=0, i;<br />
<br />
lpszServer = lpszArgv[1];<br />
cout<<lpszServer<<endl;<br />
<br />
<br />
<br />
do
{<br />
res = NetShareEnum (lpszServer, 502, (LPBYTE *) &BufPtr, -1, &er, &tr, &resume);<br />
<br />
<br />
if(res == ERROR_SUCCESS || res == ERROR_MORE_DATA)<br />
{<br />
p=BufPtr;<br />
<br />
<br />
for(i=1;i<=er;i++)<br />
{<br />
TCHAR* strPath =p->shi502_netname;<br />
<br />
cout<<strPath<<endl;<br />
CACLInfo objAclInfo(strPath);<br />
<br />
objAclInfo.Query();<br />
<br />
p++;<br />
}<br />
NetApiBufferFree(BufPtr);<br />
<br />
}<br />
else <br />
printf("Error: %ld\n",res);<br />
}<br />
while (res==ERROR_MORE_DATA);
|
|
|
|
|
as i can see from here, your real problem is probably not cout<<strPath<<endl; . I guess that cout statement is a debug output statement.
if you want to fix that part, you have to use wcout and it will print properly.
Is there any other problem in your code beside printing?
-Prakash
|
|
|
|
|
This maybe is a stupid question but I have to ask:
Are your program using UNICODE?
In that case, it's perfectly understandable:
The console doesn't want UNICODE, so when your 't' is written to the consol, the console sees a 't', followed by a \0.
And since \0 is a string terminator, the output is terminated.
Could this be the case here?
|
|
|
|
|
Yes i am programing in unicode.
So what shld i do
Kelvin Chikomo
|
|
|
|