This is what the question is stating:

Write a program that inputs a line of text using function fgets() into a char array s[90], then it outputs the line converted to uppercase.

For function fgets to be used, am i correct if I understand that the user doesn't have to input anything but the text should be get from the file only?

Keeping with the same function, I found that this is how the function is used. fgets ( char * str, int num, FILE * stream ); Am I correct if I understand that: char *str => the array of characters where the data from the text file is to be stored int num => how big the array is FILE * stream => the file where data is to be get from.
?

Recommended Answers

All 11 Replies

(since I couldn't edit post)

I have attempted this so far, but the code isn't compiling since it is saying that data types that need to be upper-ed aren't the same

#include <stdio.h>
#include<ctype.h>

int main()
{
	char line[80],ch;
	fgets(line,80,stdin);
	ch=toupper(line[80]);
	printf("your quote was : %s",ch);
	fflush(stdin);
	getchar();
   return 0;
}

While fgets() suggests reading from a file, you can pass stdin as the stream for user input.

While fgets() suggests reading from a file, you can pass stdin as the stream for user input.

Yes yes , I got that by some research on google but since the question asks to use that, I used that and made matters more simple since I haven't studied files well.

I tried the program (in the post above), but the problem now seems to be the toupper. I can't get it how toupper needs a type integer, when integers don't really have an uppercase , as long as I recall well :P

A letter is just an integer value. 41 = '1', 65 = 'A', 97 = 'a'. It all depends how you display the value, as a character or as an integer.

1) Do not edit a post after someone responds to it. It makes their response seem wrong.
2) fflush(stdin) is wrong -- see this

You are trying to print a character as a string:

printf("your quote was : %s",ch);

I'm not sure why toupper doesn't work with my IDE but try this:

printf("your quote was : %s",toupper(line));

You are trying to print a character as a string:

printf("your quote was : %s",ch);

I'm not sure why toupper doesn't work with my IDE but try this:

printf("your quote was : %s",toupper(line));

toupper() returns a single character...

@mikrosfoititis: These errors where shown.
expected 'int' but argument is of type 'char *'
format '%s' expects type 'char *', but argument 2 has type 'int'


@Narue: Is there a way I can use toupper() with a string then?

@Narue: Is there a way I can use toupper() with a string then?

Yes, the way you do everything with each character of a string: use a LOOP!

int i;

for (i = 0; line[i] != '\0'; i++)
    line[i] = toupper(line[i]);

How I wish my lecturer's notes and explanations where this way, including at least a guide that a loop should be used rather than a very unhelpful
"#include<ctype.h>
eg char ch=toupper(variable-name);"
Perhaps I should have thought it out anyways.

Thanks :]

oh yeah, silly me.
So toupper() works on only one chaarcter!

Perhaps I should have thought it out anyways.

That's usually the best solution when learning. You remember more after figuring out a solution rather than letting someone else give it to you.

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.