Question

+1 Shantanu Odak · December 21, 2015
Write a program to accept a character and display it 10 time?

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Linguist Llama · December 28, 2015
Understand that I'm not talking about things like whether a GUI is supported or not. If we keep the GUI logic separate from the processing logic, then we should be able to substitute it for something else merely by changing the compilation commands to link a different module in.

Do you think it's faster to convert a size_t returned by strlen to an int? Not only is that non-portable but it will also most likely introduce extra overhead for handling the sign... Have you thought about that?

Tell me, you wrote some drivers, right? Imagine if every program had different drivers, each one for different filesystems, rather than using fopen and friends and they never made any attempt to reuse any code. Would this be efficient? This is an example of adding architecture dependence to C code, right?

No, of course not. Reinventing the wheel for every program would not only introduce unnecessary testing, maintenance and bugs but would also thrash the CPU cache; it's for this reason that your programs share the same standard library code with other programs. Modularity goes hand in hand with portability.

I suppose you might be thinking of cases such as using right shift instead of multiplying by powers of two? Have you ever thought about how easy it would be for our compilers to do that automatically? They do far more complex optimisations, like hoisting calculations to outside of loops and detecting unreachable code, when they determine that it's safe to do so... Is it possible that your compiler doesn't perform such an optimisation because it would be incorrect (and non-portable) to do so?

How do you quantify your optimisations? How do you ensure that you're targeting the most significant bottleneck, when you're performing such non-portable optimisations? If you can't be sure that you're targeting the most significant bottleneck, is it possible that you might be pushing the most significant bottleneck further and further away from being optimal by writing code that's fast but bulky in other areas?
0 Laura Lee · December 27, 2015
Do you really care so much about portability? Especially in a language like C? When will you ever write a fully functioning, practical application that does not rely on OS functionality, in a language like C? Never. Architecture dependant code is efficient code. 
0 Linguist Llama · December 27, 2015
Ahh, I see, so you're teaching a very implementation-specific language similar to C, but not C because it's bound to a specific implementation which will make their code non-portable. Neat.
0 Laura Lee · December 25, 2015
I do not need to demonstrate I can teach people. In fact I have been teaching for a long time. I do not teach C, by teaching C. I start by teaching them about the architecture, this assembler,  registers, the stack, push and pop and call instructions. Then the compiler process and finally I let them figure out how the C code can be generated to machine level instructions and let them predict how the compiler will generate such code.
0 Linguist Llama · December 25, 2015
... and I'm sorry if you read my first post as though it's insulting. I do rub off a bit abrasively on some people. My intent was to convince you to stop spoonfeeding by appealing to your emotions, because even though there may be one in one hundred people who will actually read your code and understand what corrections needed to be made, THE OTHER NINETY-NINE will simply copy and paste and take credit for your effort. Those ninety-nine will then keep coming back, time and time again, expecting you to write code for them, even when they've graduated and the work they're expecting you to do is earning them money. Do you think you'll see any of that money?

Are you here to help people? Why get emotionally involved? You should look past the garbage that is people talking trash about you and look to the gold that is the people you try to help. 

Is doing someones homework for them really helping? You're helping them pass, sure, but unless you're willing to spoon-feed them time and time again well into when they get a career, you're kind of just convincing them to waste their tertiary funds.

What you need to do is determine what they're confused about and work on correcting that, then verify that they have actually learnt something. Have you ever heard of the Socratic method? Socrates was hated by many people because he made them feel stupid, but he also made them realise how many wrong beliefs they held.

The Socratic method is teaching by asking questions. Please read http://www.studygs.net/teaching/crtthkc.htm
0 Linguist Llama · December 25, 2015
Laura, you're new to these forums, so I can forgive you for doubting my ability to program in C. Had you seen my profile on the old forum software, you would have realised I was a moderator because I was deemed to be extremely helpful, particularly in the C section of the forum. I proved myself years ago, for years before becoming a moderator.

There are people who can vouch for this. All you need to do is ask around; it's called research. This is something you should be expecting your students to do before asking you questions. Please set a good example. It's embarrassing that someone with your credentials can come up with such wrong information.

My concern is not your ability to program in C. You have demonstrated that you can program in C, however you have not demonstrated that you can teach other people to program in C. Teaching other people doesn't involve spewing code that they don't understand at them. That's just doing their work for them.
0 chinesh doshi · December 25, 2015
#include<stdio.h>
#include<stdlib.h>

int main(){
    char str[10000];
    printf("enter the word \n");
    gets(str[10000]);
    int i=0,f,a=0,b=0,c=0,d=0,e=0;
    while(str!='\0'){
    if(str=='a')
        {
            a=1;
            break;
            }
            i++;
    }
    while(str!='\0'){
    if(str=='e')
        {
            b=1;
            break;
            }
            i++;
    }
    while(str!='\0'){
    if(str=='i')
        {
            c=1;
            break;
            }
            i++;
    }
    while(str!='\0'){
    if(str=='o')
        {
            d=1;
            break;
            }
            i++;
    }
    while(str!='\0'){
    if(str=='u')
        {
            e=1;
            break;
            }
            i++;
    }
    f=a+b+c+d+e;
    if(f==5){
        printf("YES");
    }
    else{
        printf("NO");
    }
}



what is the mistake ?
my program is about checking presence of all vowels in a word 
0 Laura Lee · December 25, 2015
That was nicely put Krootushas Gesu. But not everyone learns the same, hence not everyone should be taught or teach the same. Still he could have asked nicely rather than an insulting manner.
0 Laura Lee · December 24, 2015
Linguistic Llama, I don't need any emotional validation. Your sarcasm isn't funny either. I've been programming in C on Windows for over 12 years. I've worked with embedded devices as well as developed drivers for the Windows Kernel. Yes, I'm so awesome because I can write basic c applications. Did you get the sarcasm in that? Yes I'm also awesome because I'm far more qualified of a programmer than you could ever hope to be. Did you get the sarcasm in that? There wasn't any. If you'd like to challenge or question my ability, go for it. But don't make assumptions about me when you have no idea. Likewise, I am free to post whatever I please.  
+1 Linguist Llama · December 23, 2015
Laura Lee, I understand that you probably need some kind of emotional validation. However, spoonfeeding people answers isn't going to make you meaningful. It might make you FEEL meaningful (you're so awesome because you can write basic C programs, did you sense the sarcasm?), but all it will do is teach people that you will do their work for them; YOU ARE A PAWN TO THESE PEOPLE!

If you want to validate yourself by teaching them, then TEACH them with words instead of just giving them the answer. Find out what their actual problem is, and help them to correct their confusion or build their understanding so they can solve the problem and feel as though they've learnt how to do it themselves.
  • 1
  • 2

C

106,938 followers
About

One of the most popular languages of all time.

Links
Moderators
Bucky Roberts Administrator