A
anurag
When I use cout.write in my program, I don't get any output. But when
I use puts(), all is well with the program. Why? Btw, I program on
Turbo C++. The original program was -
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
void displayName(char[]);
void main()
{
char name[40];
cout << "Enter a name (max 40 characters): " ;
cin.getline (name, 40);
displayName(name);
getch();
}
void displayName(char a[])
{
char abbr[40];
int i = 0, j = 0, nameLen, flag = 0, n = 0;
nameLen = strlen(a);
for (; i < nameLen ; i++)
if (a == ' ')
flag++;
i = 0;
if (flag)
{
for (; n < flag; n++)
{
if (a != ' ')
{
abbr[j] = toupper(a);
abbr[j+1] = ' ';
j += 2;
}
for (; a != ' '; i++);
i++;
}
if (a != '\0')
{
abbr[j] = toupper(a);
i++;
j++;
}
while (a != '\0')
{
abbr[j] = tolower(a);
i++;
j++;
}
abbr[j] = '\0';
//cout << "The short name is " ;
puts(abbr); // HERE, cout.write JUST DOESN'T GIVE DAMN
OUTPUT.
}
else
{
//cout << "The Short name is same as original, i.e. ";
puts(a); // SAME HERE!!
}
}
PLEASE HELP. THE PROGRAM HAS GIVEN ME NIGHTMARES..!!
I use puts(), all is well with the program. Why? Btw, I program on
Turbo C++. The original program was -
#include <iostream.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
void displayName(char[]);
void main()
{
char name[40];
cout << "Enter a name (max 40 characters): " ;
cin.getline (name, 40);
displayName(name);
getch();
}
void displayName(char a[])
{
char abbr[40];
int i = 0, j = 0, nameLen, flag = 0, n = 0;
nameLen = strlen(a);
for (; i < nameLen ; i++)
if (a == ' ')
flag++;
i = 0;
if (flag)
{
for (; n < flag; n++)
{
if (a != ' ')
{
abbr[j] = toupper(a);
abbr[j+1] = ' ';
j += 2;
}
for (; a != ' '; i++);
i++;
}
if (a != '\0')
{
abbr[j] = toupper(a);
i++;
j++;
}
while (a != '\0')
{
abbr[j] = tolower(a);
i++;
j++;
}
abbr[j] = '\0';
//cout << "The short name is " ;
puts(abbr); // HERE, cout.write JUST DOESN'T GIVE DAMN
OUTPUT.
}
else
{
//cout << "The Short name is same as original, i.e. ";
puts(a); // SAME HERE!!
}
}
PLEASE HELP. THE PROGRAM HAS GIVEN ME NIGHTMARES..!!