Thanks for your help guys, I played around with your code adak and realised I was getting the bad output due to using the isspace function.. why was that the cause? The description of it in the man...
Type: Posts; User: space-oddity
Thanks for your help guys, I played around with your code adak and realised I was getting the bad output due to using the isspace function.. why was that the cause? The description of it in the man...
for practice? the poster said it was an exercise
chucked this together, not everything is declared but should give you an idea how to do it..
int i = 0;
int numAppearances = 0;
while (string[i] != '\0') {
int j = 0;
while (j <...
haha i like those answers iMalc
After doing a bit of study, I realised that the code might not be working because im incrementing text, ie. text++, when text is declared to be a const pointer. Is this allowed? If not how can I...
i fixed up that statement, but the output is still exactly the same.
more help?
just to make sure,
*text == 0
and
*text == '\0'
are exactly the same?
ahh yes that's right, \\ instead of "\, i knew that but for some reason muddled up. i think i was thinking of the case when you want to output doubequotes and you write \" my mistake.
sorry for the...
oh okay, i'd been assuming that
text != NULL
and
*text != '\0'
were the same.
thanks.
im not sure why that's happening sorry, you'll have to wait for someone else to reply on that
actually you don't have to use strncmp if you're just comparing for equality to one letter (but you don't know whether it's less than or greater than if it isn't equal). you can do something like:
...
someone?
missing an endquote? if you want to print a backslash you just put one doublequote before it:
printf("Printing a backslash: "\ Done.");
you want to compare the whole word with just one letter?...
To print a backslash you must put a doublequote before it:
printf(""\");
The strncmp function can be used to compare the first n characters of two strings and returns 0 if same, <0 if less...
I had another try at it, starting over from scratch, after trying to understand pointers better and so I utilised them more here. Unfortunately this time the function, when run, just continually...
looks like the greedy algorithm is the same as what im trying to do with my code.
if i use dynamic memory allocation for currWord there's no possibility of a memory leak when a program using the...
okay, thanks. so the code at the bottom of the first post is the way to go?
i want to trim it at words
what, i can't modify it, meaning i can't use my function on it?
But doesn't while (isspace(text) == 0) {} only do the things while it [I]isn't a space? (as opposed to == 1 which would be while it is a space)
So it couldn't be both?
I used char...
Hi, I wrote a c file to output text, making sure it doesn't go over a maximum width:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "printer.h"
i just edited my code and posed the question a little differently
Hey, I wrote this function to eliminate all leading and trailing spaces from a string..
void trim(char** str) {
char ptr[strlen(str)+1];
int i = 0, j = 0;
while (isspace(str[i]) == 1) {...