Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

king coder2.0

New Coder
Write a function declared as int stringlength(char s[])
This function’s return value is the number of characters stored in the string contained in array s. You will need to use a while loop and make use of the fact that ‘\0’ character marks the end of the string.
Write a short main program to test the function.
E.g. stringlength(“I love C”) returns the value 8.
 
What have you tried?
I do not have any experience with c but, came up with a solution in about 30 minutes.

Steps I took:
  1. Researched how to define a function and get return values
  2. Researched while loops and counting
  3. Researched how to get user input.
I will post my solution but, you will need to show what you have tried first.
Making an effort whether right or wrong is the first step in learning a programming language.
Have you ever heard the term ' It takes a lot of wrong answers to get to the right one'?
 
Last edited:
Don't know if op is coming back so, going to post code so that it may help someone in the future.
It will count spaces. Can be modified to ignore spaces.


C:
#include <stdio.h>

// Declare a function / Can store up to 100 characters/bytes
int string_counter(char s[100]);

// Define main
int main() {
    char astring[100]; // Define variable array. Can store up to 100 characters/bytes
    printf("Enter a string to be counted.\n"); // Print a string
    scanf("%[^\n]%*c", astring); // Prompt for user input
 
    // Output a string including user input
    printf("The length of ( %s ) is ( %d characters long.)", astring, string_counter(astring));
    printf("\n"); // Print a blank newline
    return 0;
}

// Define function characteristics
int string_counter(char s[100]) {
    // Define and set counter variables
    int c=0;

    while (s[c] != '\0') // Use a while loop to count characters
        c++; // Add 1 for each character in the string. Including spaces
    return c;
}

Code:
Enter a string to be counted.
I am a string of characters
The length of ( I am a string of characters ) is ( 27 characters long.)
 
Yeah right, you just keep doing everybody's homework for them.... It'll be a day job before long.
It's been an ongoing problem on this forum for a while. I'm genuinely convinced that some of them are bots programmed to ask genuine questions or paid-for-hire accounts from forum marketing sites(this one in particular and less so the other one, because people are paid a certain amount for a certain amount of posts. Once they're done, it's very rare for them to do genuine, unpaid posting from there on out).

A lot of them are also just lazy students wanting others to do their homework for them - probably because they're too lazy to do the actual work or they're too lazy to even be bothered learning any of what is taught to them.

As it stands, it's typically people such as ourselves who go about answering the questions(and maybe asking a couple), while the rest are newcomers who come and go with their questions and then there comes a point where they're never heard from again. It's because of this that I don't participate a lot on the site now: there isn't enough activity or interest in it. Which makes sense, when you consider that forums are a dying breed of website and for programming, you already have sites like SO and all of the programming communities on Reddit, so why come to a tiny forum to ask a question where it'll be harder to get a response compared to a thriving community on a ridiculously large site?

I think @menator01 is doing a good job trying to keep activity on the site up for a bit by responding to posts, which will act as an incentive for people to come back - of course, most don't, which is what makes me think of it as an also fruitless effort, but you pick up the occasional fruit along the way to keep you going that little bit longer.
 
It's been an ongoing problem on this forum for a while. I'm genuinely convinced that some of them are bots programmed to ask genuine questions or paid-for-hire accounts from forum marketing sites(this one in particular and less so the other one, because people are paid a certain amount for a certain amount of posts. Once they're done, it's very rare for them to do genuine, unpaid posting from there on out).

A lot of them are also just lazy students wanting others to do their homework for them - probably because they're too lazy to do the actual work or they're too lazy to even be bothered learning any of what is taught to them.

As it stands, it's typically people such as ourselves who go about answering the questions(and maybe asking a couple), while the rest are newcomers who come and go with their questions and then there comes a point where they're never heard from again. It's because of this that I don't participate a lot on the site now: there isn't enough activity or interest in it. Which makes sense, when you consider that forums are a dying breed of website and for programming, you already have sites like SO and all of the programming communities on Reddit, so why come to a tiny forum to ask a question where it'll be harder to get a response compared to a thriving community on a ridiculously large site?

I think @menator01 is doing a good job trying to keep activity on the site up for a bit by responding to posts, which will act as an incentive for people to come back - of course, most don't, which is what makes me think of it as an also fruitless effort, but you pick up the occasional fruit along the way to keep you going that little bit longer.
It's probably a problem on other forums too. It never occurred to me that some may be bots, but I think you are right about that, seeing for example this user posting a daft random one-line question every two weeks or so :

a.jpg
I think this is a great forum, the regulars are very helpful but it's the bots and lazy sods that are starting to make me lose interest. It annoys me no end when I (or someone else) help(s) somebody out and they don't even bother to reply. Or when they just dump their assignment, or cannot be bothered to adequately describe their problem, or even try the first steps. Never ceases to amaze how some (would-be) programmers can be so lazy and/or incoherent.

But as you say, there is is most always something to be learnt along the way of replying to a post, whereas in many cases the OP hasn't learnt anything. So I guess we have the last laugh after all 😉
 
It's probably a problem on other forums too. It never occurred to me that some may be bots, but I think you are right about that, seeing for example this user posting a daft random one-line question every two weeks or so :
It was an idea that occurred to me recently and further reinforced as I was writing my reply. I think the example you provided is good proof of that, considering the language by looks of them in those posts seem quite robotic in speech.

I think this is a great forum, the regulars are very helpful but it's the bots and lazy sods that are starting to make me lose interest. It annoys me no end when I (or someone else) help(s) somebody out and they don't even bother to reply. Or when they just dump their assignment, or cannot be bothered to adequately describe their problem, or even try the first steps. Never ceases to amaze how some (would-be) programmers can be so lazy and/or incoherent.
I've been here for a while, on and off, and it is a good forum. I think the bots and the lazy ones degrade the content quality of the site, and in return, regulars lose interest because there is no genuine, intellectual discussion. I'm with you as well on being acknowledged for your work: it's quite ignorant(and in some cases, hurtful), especially when you've put a lot of effort into a solution and you don't even get acknowledged with it. For all we know, that person might have came back along to grab the solution, and is now laughing their ass off and claiming it as their own work.

The students dumping their assignments is another problem too, despite it being against site rules. And considering it's part of the site rules, it doesn't seem to be enforced. And even if they do describe their problem, they don't even bother to explain clearly what the solution is supposed to be or even showcase any steps they've taken to reaching that goal.

I suppose we do have the last laugh as we actually learn and improve compared to any of the OPs who don't come back to analyse, to question, to discuss, etc. But as I said, you could be doing all of the work for them and they take all of the credit for it - and it probably isn't even checked if it was their work or not.

I often question why I come back here. The site seems to have its periods of ups and downs in activity - right now, I'd say it's going up but I see that quickly going back to another down period again. But with all of that, the actual quality of discussion seems to be continuously degrading, with the odd gem every so often. I keep in occasional touch with Malcolm and I discuss how to improve the site with him occasionally as well, and as a result, I go out of my way to spark discussions, however, most people don't seem to take a lot of interest and I feel that it's a worthless effort. I don't even do programming now(except for occasionally playing about with a few lines of code here and there), so why I keep coming back to a programming forum is beyond me. I really come back to try and keep my interest up, despite having completely lost interest and spending time on other things that I feel I'm actually making progress in.

In programming, I get as far as pointers and structures in C, and when I feel I'm ready to program something, I am completely overwhelmed with large projects to join and I don't even know where to begin with them. Everything has been invented; no need to reinvent the wheel. I can scroll through all of the "good first issues" all I like in a repository but I still wouldn't know where to begin. I'd like to design a half-decent game for the fun of it, but I can't seem to get Unity to work now, and again, I've just lost interest in programming so what would I gain? Trying to look for work on the site is also pointless because it's always people with their head in the clouds looking to make the next big [tech company here], and I've been asking about for a while and I've only gotten one response - from a site of almost 3500 members(a good portion of which are bots and another good portion of which are people who just don't come back), which I find ridiculous!
(Apologies for personal rant 🙂)
 
Haha yes, that was quite a soliloquy 😉 I appreciate your thoughts though. Yes it would seem that the majority of posters only come here for instant gratification, not to learn something or have a meaningful conversation. They just want somebody to fix their problem, or write their code for them. Much as I'm inclined to help someone if I can, I refuse to do that.

Sorry to hear you have lost interest in programming. Yes everything has been done already but why should that keep you from reinventing some little wheel, just for the hell of it ? I recently has some fun programming an analog/hybrid clock. Not very original but there was a lot to be learnt along the way. And I like programming some stuff for private use, just to make life a bit easier (such as syncing photos between smartphone and pc, keeping track of energy usage, and printing labels for my wife's preserves).

I keep coming back to this forum because, a couple of years into retirement, it keeps me sharp (or so I hope), and to keep my programming and troubleshooting skills (such as there are 😁 ) from sinking into oblivion. Most every post by anyone is an opportunity to learn something new. Though I have to come to grips with the fact that the ability to absorb really new stuff decreases with age. So I really hope this forum isn't going to just peter out over time, like the piano forum I was co-admin of for several years, and which just dried up eventually after some years of dwindling visitors. It could well be the time of 'small' forums like this one is over, but I hope not. I don't particularly like Stack Overflow, where there's at least 20 different answers for each question and I usually come away more confused than I was to start with... I'm a regular visitor of C# Forums, because C# is my main programming environment, and the staff there are awesomely knowledgeable and helpful, although they don't suffer fools easily.

Heehaw, one rant for another 😄
 
Oh boy, rantfest 2022!

I wasn't exactly looking for sympathy but I appreciate it anyway. My complaint was really intended to stress how hard it is to get into programming; it's touted as a necessary skill that everybody should learn going forward into the 21st century and beyond, however, I have to disagree heavily with that - like maths, it isn't for everybody. It requires concentrated, logical thinking, a deep interest, and creativity, and of course, a computer and the skills required to operate one. I laugh at how they speak of the two most recent generations(Gen Z and Gen Alpha) as being the generations that will be technically proficient because they grew up with technology all around them, however, from my own experience, a lot of them struggle with basic operations on a computer such as searching for a file or application. They are also severely distracted by technology as well through entertainment forms such as social media, streaming services, and video games - this causes them to lose interest in other things(and their work) and can also wire the brain to not be engaged in logical thinking but rather have it wired purely to seek out pleasure(I'm not going to go any further with this but I think you get the idea of where I'm going and I apologise for the strange tangent).

I'm not exactly against reinventing the wheel, as long as you can provide something fresh to the same idea. And I'm not against it either for learning. But I find a lot of simple projects to be uninteresting and very easily achievable if you put in the time and effort - I often put that time and effort into other things now. A lot of people say you should contribute to open-source projects, and I agree, but where do you start? As I said, I don't think programming is easy to get into and you need to have that determination to get into it or else you lose interest quickly - I had the determination, but I was overwhelmed by the size of the projects I wished to join and that turned me away, no matter how hard I looked for a spot to join in.

I don't hope either that the forum sizzles out: I think it will be how I mentioned it seems to be, which is periods of ups and downs in activity levels. The rise of centralized networks has contributed to the decline in forums and other forms of communication such as IRC. Not only that, but a lot of forums where valuable information was on are also disappearing, meaning we lose access to ideas, humor, arguments, etc. While it's good that the centralized networks mean that we don't need to scour the web for information, it does mean that if they go down, the damage and loss in terms of information available would be immense - smaller communication forms don't have this problem. However, I don't see forums or IM/IRC or usenet ever making a comeback: people prefer the simplicity and centralization and easy information access sites like Reddit and SO provide.

Anyways, best we keep our rants for a separate thread now, and not the thread of some random user who asked a question and will most likely never come back to respond to the answers given.
 

Buy us a coffee!

Buy me a coffee.
Back
Top Bottom