Help! I'm kinda confused on doing this program.
You have a .txt file (from Notepad) that has the following input in the first line:
1234567#John Edwards#Ohio
How can you able to view and display these outputs using the C# application, in such a way that '1234567','John Edwards' and 'Ohio' are different inputs, wherein, they are all displayed separately in a label/text button?
Is there any links I could access that involves this kind of problem? Thanks.
How to display and read .txt file using C# windows application?
I don't know C#.
But in C, I will do this like
{
FILE *fp;
fp = fopen("..........txt","r");
fscanf(fp,"%ul#%s#%s",%26amp;code,name,state...
}
The # symbol in scanf swallows the matching character in the text file. (However, the name 'John Edwards' has two parts. Only 'John' will be stored in name)
I did C long back in 1996. And I haven't practically did any project.
I just tried to help you recollecting my old days.
Reply://FilePath IS THE PATH OF THE FILE YOU NEED TO READ
StreamReader obj_StreamReader = new StreamReader(FilePath);
string str = null;
//LIST THAT SAVE THREE DIFFERENT INPUTS
ArrayList obj_ArrayList = new ArrayList();
while ((str = obj_StreamReader.ReadLine()) != null)
{
string[] strr = str.Split('#');//SPLIT THE STRING
foreach (string split_str in strr)
{
obj_ArrayList.Add(split_str);
}
//TAKE THREE LABEL CONTROLS AND CHANGE THERE NAME PROPERTY TO LBL1, LBL2 AND LBL3
//OR ANYOTHER NAME OF YOUR CHOICE. AND DO THE FOLLOWING
LBL1.Text = obj_ArrayList[0].ToString();//THIS DSPLAY 1234567
LBL2.Text = obj_ArrayList[1].ToString();//THIS DSPLAY John Edwards
LBL3.Text = obj_ArrayList[2].ToString();//THIS DSPLAY Ohio
}
Reply:check out any documentation on the System.IO name space. within the name space are several classes that deal with handling files. You will probably need to learn a little about StreamReader objects and how they allow you to read files. The File class also gives you some power in how to handle files.
Tuesday, July 14, 2009
Chess: link the players with the keyboard and move them on the chess board using c/c++?
welcome everybody,
Actually im makin a projct. somewhat related to chess in c/c++
Im up with makin the board and settin the players at appropriate positions....but im stuck on how to link the players with the keyboard or the mouse and move them on the board using c/c++ programmin......
newayzzzz thnks 4 sparing your time n readin the article....hpe helpin me out helps you revise ur basics.....
thnks again... :):p////////
Report It
Chess: link the players with the keyboard and move them on the chess board using c/c++?
This may be harder than it appears.
If you are using Windows as your platform, is easy to draw a layout of the keyboard in a window (with the pieces) and then capture the "mouse down" event. You can use a simple function to translate the mouse pointer coordinates into a map of the virtual chess board.
You can create an array of chars 8 x 8
char ch_board[8][8];
and initialize it with your pieces and special value for blank positions.
You can use this simple function to translate the mouse position to your coordinates:
#define BOARD_SQUARE_SIZE 15 /* this should be the size of a board square side */
void MouseToBoard(LPPOINT lpMouse, LPPOINT lpBoard)
{
if (lpMouse %26amp;%26amp; lpBoard)
{
lpBoard.x = lpMouse.x / BOARD_SQUARE_SIZE;
lpBoard.y = lpMouse.y / BOARD_SQUARE_SIZE;
}
else if (lpBoard)
{
/* invalid mouse input */
lpBoard-%26gt;x = 8; lpBoard-%26gt;y = 8;
}
}
After this function lpBoard is a point structure with the coordinates to the virtual chess board char array (validate for out of range values).
Another aproach to your project may be, just letting the user to type in the moves to perform by using the standard chess board coordinates (a to h columns and 1 to 8 rows).
I hope this helped.
If you need more pre-written C++ code or classes, you can visit my website:
http://negyware.110mb.com
You may find an easy to use Windows template there.
Reply:you can use C graphics. then you create 2 char[] arrays 8x8
or you can create one though!! you can save them as signs into array, so while printing you can identify the pieces. for moving, you can use keyboard, getch() and getche()
i prefer do it in Borland C++, it works much better for me. you get the key =%26gt; char _move=gethce() then you realize which ASCII character is it and you set e frame on board ... the frame moves one right and one left or up or down while you press the key. you can put it into a while(true) and set for instance if the key is ESC then get of the program of when ENTER pressed, select that piece which the frame is on it, and then you move the frame, you go to somewhere else in your board and u press enter again so the piece can be moved or @ least the program can decide first the move is valid or not! there are a lot to do and explain actually. if you wanted help pm me in yahoo =%26gt; lcx0l@yahoo.com
liama-song
Actually im makin a projct. somewhat related to chess in c/c++
Im up with makin the board and settin the players at appropriate positions....but im stuck on how to link the players with the keyboard or the mouse and move them on the board using c/c++ programmin......
newayzzzz thnks 4 sparing your time n readin the article....hpe helpin me out helps you revise ur basics.....
thnks again... :):p////////
Report It
Chess: link the players with the keyboard and move them on the chess board using c/c++?
This may be harder than it appears.
If you are using Windows as your platform, is easy to draw a layout of the keyboard in a window (with the pieces) and then capture the "mouse down" event. You can use a simple function to translate the mouse pointer coordinates into a map of the virtual chess board.
You can create an array of chars 8 x 8
char ch_board[8][8];
and initialize it with your pieces and special value for blank positions.
You can use this simple function to translate the mouse position to your coordinates:
#define BOARD_SQUARE_SIZE 15 /* this should be the size of a board square side */
void MouseToBoard(LPPOINT lpMouse, LPPOINT lpBoard)
{
if (lpMouse %26amp;%26amp; lpBoard)
{
lpBoard.x = lpMouse.x / BOARD_SQUARE_SIZE;
lpBoard.y = lpMouse.y / BOARD_SQUARE_SIZE;
}
else if (lpBoard)
{
/* invalid mouse input */
lpBoard-%26gt;x = 8; lpBoard-%26gt;y = 8;
}
}
After this function lpBoard is a point structure with the coordinates to the virtual chess board char array (validate for out of range values).
Another aproach to your project may be, just letting the user to type in the moves to perform by using the standard chess board coordinates (a to h columns and 1 to 8 rows).
I hope this helped.
If you need more pre-written C++ code or classes, you can visit my website:
http://negyware.110mb.com
You may find an easy to use Windows template there.
Reply:you can use C graphics. then you create 2 char[] arrays 8x8
or you can create one though!! you can save them as signs into array, so while printing you can identify the pieces. for moving, you can use keyboard, getch() and getche()
i prefer do it in Borland C++, it works much better for me. you get the key =%26gt; char _move=gethce() then you realize which ASCII character is it and you set e frame on board ... the frame moves one right and one left or up or down while you press the key. you can put it into a while(true) and set for instance if the key is ESC then get of the program of when ENTER pressed, select that piece which the frame is on it, and then you move the frame, you go to somewhere else in your board and u press enter again so the piece can be moved or @ least the program can decide first the move is valid or not! there are a lot to do and explain actually. if you wanted help pm me in yahoo =%26gt; lcx0l@yahoo.com
liama-song
Playing AVI videos(or any other format) using C++?
Hello,I need urgently to know how to play an AVI vedio(or any other video format) in a Visual C++ Win32 project's EXE (or even in a pop-up player that plays the AVI immediatly).As I want to add several short videos in my game that is implemented using Visual Studio 6 with DirectX 9 (June 2006).
Playing AVI videos(or any other format) using C++?
Check out http://www.pscode.com for great sample codes.
Playing AVI videos(or any other format) using C++?
Check out http://www.pscode.com for great sample codes.
Program to do Billing in a shop using c++?
I wanted to write a program to print a bill in a cooperative store using c++.The bill of each customer is accumilated and at the end of a month the bill is added up to get a grand total .I want to store every bill created to be stored in seperate files.Is it possible to generate files dynamically in an order like bill1,bill2....bill[i] by default OR can u suggest an alternative method to solve the problem
Program to do Billing in a shop using c++?
You'd be better off using a database to manage your data. Then you could connect to the database from c++.
Reply:The easiest way would be to append a Date/time to the file name: There are a number of different ways you can turn the current time into a string. Here is just one example http://www.cplusplus.com/reference/clibr...
If you really want a sequenced name, as ugly as this seems, this is probably the most efficient. (Windows-centric). Just call ::OpenFile with the CREATE_NEW flag. It will fail if the file name already exists. Just start with Bill_1, Bill_2, etc until one finally succeeds. This seems ugly, but it's more efficient than Using FindFirstFile and FindNextFile to get all the file names in the directory, then parsing and interpreting them to find what the next file name should be.
A quicker, but ugly way is to just try to create the file name, using the flag CREATE_NEW in ::OpenFile (again, windows-centric). If a file of that name already exists, the function will fail. Just try the next sequenced name until it finally succeeds. Ugly, but effective. Faster than analyzing the file names from FindNextFile.
Program to do Billing in a shop using c++?
You'd be better off using a database to manage your data. Then you could connect to the database from c++.
Reply:The easiest way would be to append a Date/time to the file name: There are a number of different ways you can turn the current time into a string. Here is just one example http://www.cplusplus.com/reference/clibr...
If you really want a sequenced name, as ugly as this seems, this is probably the most efficient. (Windows-centric). Just call ::OpenFile with the CREATE_NEW flag. It will fail if the file name already exists. Just start with Bill_1, Bill_2, etc until one finally succeeds. This seems ugly, but it's more efficient than Using FindFirstFile and FindNextFile to get all the file names in the directory, then parsing and interpreting them to find what the next file name should be.
A quicker, but ugly way is to just try to create the file name, using the flag CREATE_NEW in ::OpenFile (again, windows-centric). If a file of that name already exists, the function will fail. Just try the next sequenced name until it finally succeeds. Ugly, but effective. Faster than analyzing the file names from FindNextFile.
Program for printing amstrong numbers within 1000 using c language?
give complete program details using c language
Program for printing amstrong numbers within 1000 using c language?
PROGRAM ArmstrongNumber
IMPLICIT NONE
INTEGER :: a, b, c ! the three digits
INTEGER :: abc, a3b3c3 ! the number and its cubic sum
INTEGER :: Count ! a counter
Count = 0
DO a = 0, 9 ! for the left most digit
DO b = 0, 9 ! for the middle digit
DO c = 0, 9 ! for the right most digit
abc = a*100 + b*10 + c ! the number
a3b3c3 = a**3 + b**3 + c**3 ! the sum of cubes
IF (abc == a3b3c3) THEN ! if they are equal
Count = Count + 1 ! count and display it
WRITE(*,*) 'Armstrong number ', Count, ': ', abc
END IF
END DO
END DO
END DO
END PROGRAM ArmstrongNumber
Reply:int cube(int n)
{
return n*n*n;
}
main()
{
int i;
for(i=0;i%26lt;1000;i++)
{
if ( i == cube(i%10) + cube((i/10)%10) + cube((i/100)%10))
{
printf("%d\n", i);
}
}
}
Reply:here is the program to print armstrong numbers from 1 to 1000
#include%26lt;stdio.h%26gt;
main()
{
int a,b,c,d;
for(a=1;a%26lt;=1000;a++)
{
c=a;
d=0;
while(a!=0)
{
b=a%10;
a=a/10;
d=(b*b*b)+d;
}
a=c;
if(d==c)
printf("\narmstrong number %d\n",c);
}
Reply:#include%26lt;stdio.h%26gt;
void main()
{
int i=0, a=0,b=0,c=0,sum=0;
for(i=0;i%26lt;999;i++)
{
sum=0;
a=i%10; /* Units Digit */
b=(i%100-a)/10; /* Tenths digit */
c=(i%1000-(b*10+a))/100; /*100ths Digit*/
sum= (a*a*a) + (b*b*b) + (c*c*c);
if(i==sum)
printf("Armstong Number: %d\n",sum);
}
}
Reply:The asker asked for it in C.
Check out this link - it has a version in C
Program for printing amstrong numbers within 1000 using c language?
PROGRAM ArmstrongNumber
IMPLICIT NONE
INTEGER :: a, b, c ! the three digits
INTEGER :: abc, a3b3c3 ! the number and its cubic sum
INTEGER :: Count ! a counter
Count = 0
DO a = 0, 9 ! for the left most digit
DO b = 0, 9 ! for the middle digit
DO c = 0, 9 ! for the right most digit
abc = a*100 + b*10 + c ! the number
a3b3c3 = a**3 + b**3 + c**3 ! the sum of cubes
IF (abc == a3b3c3) THEN ! if they are equal
Count = Count + 1 ! count and display it
WRITE(*,*) 'Armstrong number ', Count, ': ', abc
END IF
END DO
END DO
END DO
END PROGRAM ArmstrongNumber
Reply:int cube(int n)
{
return n*n*n;
}
main()
{
int i;
for(i=0;i%26lt;1000;i++)
{
if ( i == cube(i%10) + cube((i/10)%10) + cube((i/100)%10))
{
printf("%d\n", i);
}
}
}
Reply:here is the program to print armstrong numbers from 1 to 1000
#include%26lt;stdio.h%26gt;
main()
{
int a,b,c,d;
for(a=1;a%26lt;=1000;a++)
{
c=a;
d=0;
while(a!=0)
{
b=a%10;
a=a/10;
d=(b*b*b)+d;
}
a=c;
if(d==c)
printf("\narmstrong number %d\n",c);
}
Reply:#include%26lt;stdio.h%26gt;
void main()
{
int i=0, a=0,b=0,c=0,sum=0;
for(i=0;i%26lt;999;i++)
{
sum=0;
a=i%10; /* Units Digit */
b=(i%100-a)/10; /* Tenths digit */
c=(i%1000-(b*10+a))/100; /*100ths Digit*/
sum= (a*a*a) + (b*b*b) + (c*c*c);
if(i==sum)
printf("Armstong Number: %d\n",sum);
}
}
Reply:The asker asked for it in C.
Check out this link - it has a version in C
How can creat a graphical interface by using C language?
who can creat a graphical interface by using C language? I need your help . Thank you very much!!! Can you give me an example?
How can creat a graphical interface by using C language?
Using a third party library.
http://en.wikipedia.org/wiki/Widget_tool...
Google terms: Widget toolkit, GUI toolkit, Win32 API, MFC, Winforms, GTK+, QT, FLTK, WxWidgets, etc.
Reply:I have been using Qt for a few months and like it. It is C++ not C though. There is a free version or a paid version if you are going to sell your code. It runs on windows, linux, and mac so your code could be portable. What are you doing with it? That will help you narrow it down.
garden state
How can creat a graphical interface by using C language?
Using a third party library.
http://en.wikipedia.org/wiki/Widget_tool...
Google terms: Widget toolkit, GUI toolkit, Win32 API, MFC, Winforms, GTK+, QT, FLTK, WxWidgets, etc.
Reply:I have been using Qt for a few months and like it. It is C++ not C though. There is a free version or a paid version if you are going to sell your code. It runs on windows, linux, and mac so your code could be portable. What are you doing with it? That will help you narrow it down.
garden state
How to get client's ip address using c# asp.net?
Im creating a website using c# asp.net, and now i need to get the client's Ip address , how do ill get in coding , please any one give me the solution for it
How to get client's ip address using c# asp.net?
Request.ServerVariables("REMOTE_ADDR")
Reply:What he said, but if it's C#, use the [ brackets, not the (.
Reply:No big deal. Ask him!
Reply:try this...
l1.Text += Request.UserHostAddress;
l2.Text += Request.UserHostName;
l3.Text += Request.Browser.Browser;
hope this helps... try also to visit the link(source)
How to get client's ip address using c# asp.net?
Request.ServerVariables("REMOTE_ADDR")
Reply:What he said, but if it's C#, use the [ brackets, not the (.
Reply:No big deal. Ask him!
Reply:try this...
l1.Text += Request.UserHostAddress;
l2.Text += Request.UserHostName;
l3.Text += Request.Browser.Browser;
hope this helps... try also to visit the link(source)
Subscribe to:
Posts (Atom)