Yeah, I have since figured that out.
However, for my own purposes, I wanted to get rid of the \n being stored at the
end of the string so I'm using it like:
...
Type: Posts; User: w2look
Yeah, I have since figured that out.
However, for my own purposes, I wanted to get rid of the \n being stored at the
end of the string so I'm using it like:
...
Thanks for the suggestion!
I tried:
fgets(ptrNew->fname,40,stdin) ;
ptrNew->fname[strlen(ptrNew->fname)]='\0';
Thanks, that was actually my next question.
I'll give gets a whirl and see if I can make it work.
Hi, I am writing a contact book program using linked lists and I want to fill the
elements of the lists character by character. The reason I want to do it char by char
is to allow spaces when I...
Sometimes you just have to walk away from the computer and clear your head.
The solution came to me as I was cooking breakfast this morning.
You have to pass it two pointers. One to the start...
This is what the constraints of the project are:
Write a function called Reverse that accepts as a parameter a char array (or char pointer)
and returns a void. The function reverses the contents...
I am not looking for a coded solution!
Please just point me in the direction of how to fix what I am doing wrong if you can.
I am working on a project for class to reverse a string. I have...
Why not?
The next part of the problem involved taking the newly "parsed" array of words, sorting them in alphabetical order and then printing them.
//prototypes
void ParseSentence(char...
Actually, I think I got it!
Changed the code in the for loop to:
for(i = 1; i < size - 1; i++)
{
words[i] = strtok(NULL, " .,;");
I see what you're saying, I have since moved on to the next part of this problem and it is causing me problems. While I am getting the printed output I desired, the words are not being stored in the...
OK, this time I think I've got it.
void ParseSentence(char *ptrA)
{
char temp[80];
int i;
strcpy(temp, ptrA);
looks like I spoke too soon.
no more seg fault, but not printing past the first word
hmm?
I don't know what I was thinking, I didn't need a while loop at all.
If I was smarter and read your advice thoroughly, I would have saved myself some time.
i.e. "You need to print until you run...
I'm not quite sure where you got the # 40 from. The default size of the buffer for user input is 80 chars. But what you suggest makes sense. I guess I should be using a while loop instead of a for...
I thought that there may be a possibility of another part of my program causing the problem
so I put everything regarding this function into it's own program to try and isolate the problem.
Here is...
Tried changing it to this, but same result.
void ParseSentence(char *ptrA)
{
char temp[80];
char *words[80];
strcpy(temp, ptrA);
Do I use an if statement for that?
like
if (character == NULL)
break;
Should I be copying the char array being passed to the function into a temp array before using strtok?
If so, how do I do that? I'm kinda new to C.
OK, I changed the code to the following.
Still getting the same result.
//prototype *was wrong in initial post*
void ParseSentence(char *ptrA);
//call in main
ParseSentence(Buffer3);
I am writing a function to parse a sentence and print each separate word on a new line.
For some reason, I keep getting a Seg fault. Can anyone please tell me what I am doing wrong?
It is...
Wow!
Thanks for all the replies.
I actually got it to work while I was away from the board.
However, I did it by cheating.
The function I wrote will return the array with all the elements...
OK, here is what I have come up with.
void LeftShift2D(int array [R] [C])
{
int lim = R * C;
int temp = array[R-1] [C-1];
for(int i = lim - 1; i >= 0; i--)
So I guess I should use 2 temporary variables then.
One for the first element that I will keep until the end
And one to temporarily keep the elements that I'm moving.
How do I keep from...
I am rather new to C programming and I am trying to learn as much as possible.
We recently had an assignment centered around 2D arrays.
We had to write several functions...
...
You have all been a great help and I think that I may have
taken a little something from each of you in the way of
advice to finally finish the problem.
This is what I have come up with and...