Hi... I have a project whic is input should be like...

Kazma 7 780 m
Kaz 13 1400.5 f
Azaz 1 601 m

and output should be like....

Kazma 7 ,,,,780.00 "m"
,,,,,Kaz 13 1400.50 "f"
,,,Azaz 1 ,,,,601.00 "m"

(please think without , )

In this project input can be changeable but output looks must like this. As you see first words should be right aligned. Then number should be after one space then next number should be right aligned with point(.) last one is m or f should be in ""....
now I think first words I am gonna use in the string.. next number should be integer . other one is double last m or f should be char.....
I think I can handle the others but I dont get the first ones. How can I aligned to these words to right???? Any clue????? Please give simple c+ I dont understand c++ :(

If this is in c++, you should look up some of the things made available in <iomanip>. The code won't be very neat, but you can eventually get it to output to pretty much any format. You might have to find out what the longest value for some columns are to make sure it all lines up correctly.

I'd read in the file one field at a time storing the information in a struct that I'd then store in a container. As I was reading in the first field I'd check it against the current longest name. When I'd read in the entire file the longest name would determine how wide the first name would need to be. I'd probably do something similar for the other fields as well. Then, using either format modifiers in C or output manipulators in C++ I'd create the output format.

I need to learn how to type faster!

ok then I will try to find the biggest word then I will align to rigth... But not today its too late in here... I still need your advices keep on thanks all of you.........

guys I didint get the ıdea.... I think I have to sent all inputs into the arrays... am I right?? then I have to check which one is longest for first entered words?? is that right?

int mystrlen(char *);
void main(void)
{     char str1[80];
      printf("Enter your string: ");
      printf("Length of the string %s is %d.\n",str1,mystrlen(str1));
int mystrlen(char *g)
  int i=0;
  while(*(g+i) != '\0')
  return i;

I can now calculate the length of strings with that ... then I am gonna compare the other strings that I am gonna enter..but how can I write it rigth aligned???? please help....

Read about the printf format string -- you can specify the field width for strings and whether they are left or right aligned.

int main()
	printf("%20s\n", "Hello");
	printf("%20s\n", "Hello World");
	return 0;

That will print the word "Hello" in a field that is 20 characters wide and right aligned. add a minus symbol before the 20 to make it left-aligned

why don't you use the standard c function strlen() instead of re-inventing the wheel? Or is it required by your instructor to do that?

Read Lerner's suggestions -- they are good ones.

I know that but my project is little bit confusing... I dont know the space, space will determine with I entered string lenght.
I can now write without strlen or other codes.. I can change



with couple of while and some math calculations :)
I calculate the all words lengt and compare.. then find the biggest and I make printf(" ") untill reach the biggest.
I did it but I wanna know how strlen works? is that very simple that than???
my other question is how can ve write quote (") on the screen.. ı cant do that.........

You don't need a while loop to print the spaces. Just use a variable instead of hard-coding the field width as in my previous example. Just replace the 20 with an asterisk and add the width variable

int width = 20;
printf("%*s", width, "Hello");

>>my other question is how can ve write quote (") on the screen.. ı cant do that

you have to use escape character befor it, like this: printf(" \"Hello\" ");

thank you so much it will erase my 9 lines of code :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.