|
|
You have: char *s3 = "..." . Although s3 is declared as char * the type of the string is const char * . Use char s3[] = "..." instead.
|
|
|
|
|
|
If I were to hazard a guess, I'd say it has to do with aux being destroyed (i.e., going out of scope) once my_strdelupper() returns.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I think you are correct, but I tried to copy aux to s and didn't work, now I changed the code to send an array, them befour I leave I copy using srtcpy aux to s, and it's working.
|
|
|
|
|
This line of code puzzles me:
*(s + i) != '\0' < len It probably should be:
i < len
A second problem is that you are doing the copy only on !isupper, when you should be doing it always as soon as an uppercase character is detected.
A third problem is the strcpy() at the end. It's pointless.
A fourth problem is that you are returning a pointer to the a stack value which becomes invalid because the call to printf is likely overwriting it and is likely causing a fault.
modified 8-Jun-19 1:10am.
|
|
|
|
|
You are correct, that was one mistake, but it should be *(s + i) != '\0' because I am searching for the end of line.
|
|
|
|
|
Try this:
char* my_strdelupper(char* s){
int i, len;
char* sl;
len = strlen(s);
sl = (char*)malloc(len+1); i = 0; while (*s != '\0'){
if (!isupper(*s)){
sl[i++] = *s; }
s++;
}
sl[i] = '\0';
printf("%s\n", sl);
return sl;
}
|
|
|
|
|
The stupid thing is that I can't use malloc, so I made a char array with fixed size to overcame that problem.
|
|
|
|
|
Thank you, for all, it was a great help.
The problem was solved by:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define false 1
#define true 0
char* my_strdelupper(char* s){
int i,j, len;
char aux[100];
char debuging;
len = strlen(s);
j = 0;
for (i = 0; *(s + i) != '\0'; i++){
if (!isupper(*(s+i))){
debuging = *(s + i);
*(aux + j) = debuging;
j++;
}
}
*(aux + j) = '\0';
strcpy(s, aux);
return s;
}
int main()
{
char s3[]="Maria, TU sabes que TU éS o meu \"Grande Amor\"";
printf("%s\n",my_strdelupper(&s3[0]));
return 0;
}
|
|
|
|
|
As a note - you define 'len' but you don't use it.
Presumably the assignment does not say otherwise, using that would make your code simpler.
|
|
|
|
|
Note you don't need extra storage, the function may change the string in place:
char * remove_upper( char * s)
{
char * p, *q;
for (p = q = s; *p != '\0'; ++p)
if ( ! isupper(*p) )
*q++ = *p;
*q = '\0';
return s;
}
|
|
|
|
|
Taken from K&R 1st ed? Certainly has that feel>
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012
|
|
|
|
|
It is the Wonderful C programming language, of course has such a feel.
In any case, were Dennis and Brian the ones who plagiarized my programs. 
|
|
|
|
|
I was begging to think no one here was thinking.
Thanks
INTP
"Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra
"I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone
|
|
|
|
|
I have copied a program from CrazyGeeks website and modified some of its statements. Anyone please tell me whats wrong in below code:
#include <iostream>
using namespace std;
int main()
{
int count, j, elements[50], search_num, first, last, mid;
cout<<"Enter the total number of elements :";
cin>>count;
cout<<"\nEnter ">>count>>" numbers:\n";
for (j=0; j<count; j++)
{
cin>>elements[j];
}
cout<<"\nWhich number that you want to search: ";
cin>>search_num;
first = 0;
last = count-1;
mid = (first+last)/2;
while (first <= last)
{
if(elements[mid] > search_num){
first = mid + 1;
}
else if(elements[mid] == search_num){
cout<<search_num<<" found in array at "<<mid+1<<"\n";
break;
}
else {
last = mid - 1;
}
mid = (first + last)/2;
}
if(first > last){
cout<<search_num<<" Not found in an array";
}
return 0;
}
Code link
|
|
|
|
|
Quote: cout<<"\nEnter ">>count>>" numbers:\n";
Should be
out << "\nEnter " << count << " numbers:\n";
You should ask the user for an ordered sequence, in order to make the binary search work.
Your code is very C -like, you didn't take advantange of the wonderful features of modern C++ . 
|
|
|
|
|
|
|
You should format your code snippet with the proper indentations.
|
|
|
|
|
Hi!
I am currently working on a project that is used to the global event.
I did not find any vague suggestions on google.
Show me how to start it and document it.
Thank you!
|
|
|
|
|
I'm having diffculty to understand what you're looking for, and I suspect for google it's the same.
Let's start with specifiying more clearly what you want to do:
- what is a typical usecase for the program that you want to solve?
- what are the conditions under which the program is used?
- who uses the program?
- who writes the program (other than you)?
And more to the point:
- what do you mean by global event?
- what do you mean by 'start' and 'document' and 'it'
I do have some ideas what you're talking about, but it would be easier to offer meaningful advice when there's less guessing involved.
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thanks for your answer!
I'm looking to build a demo to use to the global event.
I want to write a program (MainApp) that manages two other programs (SubApp1 and SubApp2). When I run MainApp, then MainApp will start subapp1 and subapp2.
|
|
|
|
|
1. You still haven't told us what you mean by global event
2. You're talking about processes and threads. Typically when you start an application on your computer, this starts a process with a single thread, the main thread. You can choose to leave it at that, in which case your program will just sequentially process it's task. Or your process can create new threads controlled by it, which will potentially run in parallel. You can also start a new process from the first one, but then your initital process will have no direct control over it; it can only talk to it via interprocess communication protocols.
In that latter case, communication might be implemented by sending Windows Events to the other process. I'm sure there are many other ways, but I'm not up to date with modern approaches in this field, nor do I have any relevant experience.
So, when you talk a 'mainapp' and 'subapp's, do you mean a process and it's threads, or do you mean to spawn separate processes - in which case the term 'subapp' would be very misleading?
P.S.: I only now spotted your answers below - looks like I was on the wrong path all along. As CPallini said, you'd better ask at the Kentico forums. And as they're using C#, the question is if you really want to go the extra mile of trying this in C++ ...
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Thank you very much for your support!
|
|
|
|