Ashish
#include<stdio.h> int main () { int a,b; int length; int array[9]; printf ("Enter Length of the array: "); scanf ("%d", &length); printf ("Give the range [a,b]: "); scanf ("%d %d", &a ,&b); printf ("Number from the range[%d,%d]: ", a, b); for (int i = 0; i < length; i++) { scanf ("%d", &array[i]); } for (int j = 0; j < length; j++) { if (array[j] > 0) { printf("%d\n",array[j]); } else{ continue; } } }
#include <iostream> #include<conio.h> using namespace std; int main() { int a,b; int length; int array[9]; cout<<"Enter Length of the array"; cin>>length; cout<<"Give the range [a,b]"; cin>>a>>b; cout<<"Number from the range"; for (int i = 0; i < length; i++) { cin>> array[i]; } for (int j = 0; j < length; j++) { if (array[j] > 0) { cout<<",array[j]"; } else{ return 0; } } }
³*hug#⁸
/test
Anonymous
/test
Al
Can someone translate for me into c++?
mo need , C is a subset of C++ mostly and this little program is included
Avinash
Hello everyone ! I need a suggestion in designing my project. There are 2 programs: producer & consumer. * Producer acts like a virtual hardware and generates a stream of uint8 numbers (randomly picked for now). * Consumer reads data from this stream and processes it. I'm not much familiar with inter-process communication. Read about it but here I have to maintain a Queue (in Producer) which is constantly being written (by random numbers) and parallely the Queue's data is being sent & removed. Further, I want to send it in packets when either buffer overflows or timeout happens. Don't know how to create observer for this buffer. Any help or direction on this ?
Mad
// ex06_17.c // What does this program do? #include <stdio.h> #define SIZE 10 int whatIsThis(const int b[], size_t p); // function prototype // function main begins program execution int main(void) { int x; // holds return value of function whatIsThis // initialize array a int a[SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; x = whatIsThis(a, SIZE); printf("Result is %d\n", x); } // what does this function do? int whatIsThis(const int b[], size_t p) { // base case if (1 == p) { return b[0]; } else { // recursion step return b[p - 1] + whatIsThis(b, p - 1); } } I didn't understand after //(what does this function do). what does it mean of these lines
Mad
espacially, I didn't understand this line (else { // recursion step return b[p - 1] + whatIsThis(b, p - 1);)
Alex
it returns given array element by element. recursion - function <name> calls function <name>
IAmMADMAX
Calkin-Wilf Program anyone?
Alex
Can you explain how is it print this line
it returns sum of elements, not prints.
M
Hello . Have anybody work with c in Xcode ? I have to use in my project but I have difficulty to add or install headers . How can I install c headers in Xcode ?
Igor🇺🇦
Anyone?
getline extracts characters from input and appends them to str until one of the following occurs (checked in the order listed) a) end-of-file condition on input, in which case, getline sets eofbit. b) the next available input character is delim, as tested by Traits::eq(c, delim), in which case the delimiter character is extracted from input, but is not appended to str. c) str.max_size() characters have been stored, in which case getline sets failbit and returns. https://en.cppreference.com/w/cpp/string/basic_string/getline
Ishikawa
Hello! How to make softwares that do not directly add text to current window but like open by clearing everything on screen and then restore everything when exitted. Something like Vim compared to ffmpeg.
Ishikawa
How is it done, are there libraries for doing this kind of thing?
Anonymous
Hi
Dima
lol wow such suspicious
Anonymous
Anyone help me i have to learn c++
Harsha [M]
Ishikawa
How is it done, are there libraries for doing this kind of thing?
Like 'Vim' compared to 'cat'
Ishikawa
If somebody could spare a minute helping me. 😅
Vedant
Please take Jetbrains Developer Ecosystem Survey 2021 Let's make developer tools better https://surveys.jetbrains.com/s3/developer-ecosystem-survey-2021-sh?pcode=105826214887201792
Igor🇺🇦
If somebody could spare a minute helping me. 😅
It's not a minute. It's system dependent , low level and not standardised. You need to play with control characters https://en.wikipedia.org/wiki/Control_character. Maybe this library can help http://www.cs.ukzn.ac.za/~hughm/os/notes/ncurses.html
Anonymous
#define UP 72 Hi, what is the meaning of 72 here?
Anonymous
Okay, thank you
Anonymous
Couldn't find it
Igor🇺🇦
I get the idea. Thank you very much.
The fact that you needed to be very platform specific is the main reason why windows console couldn't be updated. It was easier to create totally new windows terminal. Any change to console could break existing apps. More info here https://devblogs.microsoft.com/commandline/windows-command-line-backgrounder/
A N
🤚
A N
Hi
Anonymous
Hello! How to make softwares that do not directly add text to current window but like open by clearing everything on screen and then restore everything when exitted. Something like Vim compared to ffmpeg.
On vt100 compatible terminals the escape sequence is: char *saveSCR_ANSI = "\x1b[?1049h"; char *restoreSCR_ANSI = "\x1b[?1049l"; void ansi(char *esc) { printf("%s", esc); fflush(stdout); } Old DOS programs could read video memory and save/restore the char-attributes directly, but ANSI terminals have to ask the terminal to do it. A terminal might only save one screen at a time...
Anonymous
I'm not sure if all terminals have those capabilities and don't know the termcap(5) names. Libraries like ncurses maintain a record of what it thinks the screen looks like in software. Many terminal programs use ctrl-L to refresh screen if ever needed.
The escape sequence is technically "Show Alternate Screen" and has the termcap names "TI" / "smcup". Restoring the regular screen is called "Show Normal Screen" and has the termcap names "TE" / "rmcup". Actually not all terminals have these and there are also variations that don't clear the buffer when switching... This is the best single source of explaination: https://stackoverflow.com/questions/39188508/how-curses-preserves-screen-contents http://xn--rpa.cc/irl/term.html
Ajit
/notes
Anonymous
/notes
Bottom G
/get imhacker
Bottom G
/get great
Anonymous
Hi everyone I have a question Why do we need a nested function ?Cannot we do without it ? Or is it unavoidable ?Thanks in advance
Alex
Hi everyone I have a question Why do we need a nested function ?Cannot we do without it ? Or is it unavoidable ?Thanks in advance
to use scope(closure) of a function in which nested func is included, to not add another name to external entity, can do without it
Sandro
On vt100 compatible terminals the escape sequence is: char *saveSCR_ANSI = "\x1b[?1049h"; char *restoreSCR_ANSI = "\x1b[?1049l"; void ansi(char *esc) { printf("%s", esc); fflush(stdout); } Old DOS programs could read video memory and save/restore the char-attributes directly, but ANSI terminals have to ask the terminal to do it. A terminal might only save one screen at a time...
At default DOS was not compatible with standard ANSI, in order to do it you had to load ANSI.SYS in CONFIG.SYS... I honestly preferred to write and read directly in the video memory more efficient, more compatible with all CONFIG.SYS with or without ANSI.SYS, and more funny😂👍
Anonymous
Does anyone know how to fix exc_bad_access?
Anonymous
I have created a c++ project from xcode and didn't change anything at all But when I try to debug it, i get this error.
Anonymous
#include <iostream> int main(int argc, const char * argv[]) { return 0; }
Anonymous
This is my code.
Anonymous
I don't understand what is the reason.
Anonymous
My Xcode version is 11.3.1
Anonymous
I think there isn't any problem in the code. Maybe this is the project settings problem
Anonymous
#include <stdio.h> void print_matrix(int x, int y, int matrix[][x]) { int i, j; for (i = 0; i < y; ++i) { for (j = 0; j < x; ++j) { printf("[%i]", matrix[i][j]); } putchar('\n'); } } int main() { int matrix[][2] = {{0, 1}, {2,3}}; print_matrix(2, 2, matrix); return 0; } Could you guys tell me what should i write for function prototype
Anonymous
Try using char *argv[] or char **argv, it might not be the problem but worth trying.
Anonymous
I tried in multiple target but didn't work
Nils
template<typename T> class AutoPtr { T *elem; public: template<class... Args> AutoPtr(Args... args) { elem = new T(args...); } ~AutoPtr() { delete elem; } inline T& operator *() { return *elem; } void reset() { delete elem; elem = new T; } }; Does this look like fully valid C++ code to you? It feels like something is wrong but I can't tell what. It compiles tho
Anonymous
It's valid but bad C++
Nils
It's valid but bad C++
okay, how is it bad? would you help me improving that?
Anonymous
Why would you even need your own smart pointer class?
Nils
just for learning purposes
Like, just to know if I can do this and what is improvable with my result
Nils
and seems like it is definitely improvable
Anonymous
Nothing tricky, just bad :)
Did you notice the iteration constructor
Anonymous
okay, how is it bad? would you help me improving that?
For example you copy arguments to the constructor instead of forwarding them
Anonymous
Did you notice the iteration constructor
What is the iteration constructor? ;)
Anonymous
okay, how is it bad? would you help me improving that?
Reset shouldn't create a new object
Nils
Reset shouldn't create a new object
in my class it is intended, so you can reconstruct it at any time
Anonymous
What is the iteration constructor? ;)
template<class....>