coal
but if you're doing something like image processing, which does not really require "bruteforcing" the solutions, then Python is great due to its large support
coal
in the end though, it all reduces to what you feel most comfortable with
M. Wahyu
M. Wahyu
Melbgm
ch = getchar();
if (ch ==1)
Melbgm
what was the syntax when i write it with numbers guys ?
Felix
use %d
\Device\NUL
what was the syntax when i write it with numbers guys ?
C/C++ use ASCII char (Though you can still use unicode char16_t char32_t or wide wchar_t characters)
ASCII char has own values (see ASCII table or man ascii)
getchar() return int value that represented ascii char from the input. cmiiw
So if you compare it with 1, it won't be true since 1 is number for SOH(start of heading) character
But...., this is different
'1' with 1 is different
'1' will turn into ASCII char value which is 49.
I think, you want to compare with ASCII value directly rather than comparing with character, so it would be if (ch == 49)
Melbgm
hossein sharifi
☹️☹️
Guruphem
Write a C and Python program that will transform an arithmetic expression into postfix and prefix expression.
- Algorithms
- Flowchart
- Source Code
Guruphem
My SIWES project, is there anyone that can help? 😭😭😭
Hanz
Brown
My string variable contains = "[2,162552, {"customData": "Xyz",
"Iccid": 0009877}]"
How can I convert it into an array of strings?
ARYA
Hello, can anyone write this code?
Write a program that takes n input from the user
Then make a presentation from 1 to n
And then print all the subsets of this presentation in the following order
Like
N = 4
Array = [1.2.3.4]
Cout:
{ }
{1}
{1.2}
{1.3}
{1.4}
{1.2.3}
{1.2.4}
{1.3.4}
{1.2.3.4}
{2}
{2.3}
{2.4}
{2.3.4}
{3}
{3.4}
{4}
Sandeep
the best for everyone
what are the mistakes in this code ?
Gaurav (a.k.a Avenger)
#include <stdio.h>
int main()
{
int a,b,j;
char ch;
do{
/*Even odd program*/
printf ("\n Enter no. check weather it's even or odd= \n"); scanf ("%d",&a);
if(a%2==0) printf ("Number is even \n"); else printf ("Number is odd \n");
/*Even odd program ends*/
/*Display last digit program*/
b=a%10; printf("Last digit: %d \n",b);
/*Display last digit program ends*/
/*Display all positive no below the number program*/
j=a;
for (;j>0;j--)
{
printf ("\n %d \n",j);
}
/*Display all positive no below the number program ends*/
/*While Statement*/ printf ("Do you want to continue: y/n");
ch = getchar(); getchar();
} while(ch=='y');
}
Gaurav (a.k.a Avenger)
Pavel
Code is not going in loop
So, it does the first iteration, but if you type "y" it finishes the program instead of doing the next iteration? Or is it something else?
Marcin
what is the best design pattern for informing "creator" about events. My problem is: there is a server which creates sessions objects. I want to make that every session is able inform server about events (for example session clossgin etc.)
Joo
Can someone explain containers to me and their applications in C++
\Device\NUL
\Device\NUL
'\0' is different with "\0"
"\0" are array of char {'\0', '\0'}
Typo on priuntf
I dont't think you need variable beside for iterating since you have the length from stringlength function
It would be
for (size_t i = len - 1; i >= 0; i--)
putchar(s[i])
\Device\NUL
Sheesh, how hard to read any message from compiler before asking in the group
Gaurav (a.k.a Avenger)
shriman_deepak
// Find the lowest frequency character in a string.
#include<stdio.h>
int strleng(char str[])
{
int i = 0;
while (str[i] != '\0')
{
i++;
}
return i;
}
int main()
{
char str[100];
gets(str);
int n = strleng(str);
int max = n;
char ch;
for (int i = 0; i < n; i++)
{
int cnt = 1;
for (int j = i+1; j < n ; j++)
{
if (str[i] == str[j])
{
cnt = cnt + 1;
}
}
if (cnt <= max)
{
max = cnt;
ch = str[i];
}
}
printf("%c",ch);
return 0;
}
shriman_deepak
can anyone tell me what's wrong in this code ?
shriman_deepak
Lieutenant
shriman_deepak
if a person don't feel well doctor do some checkups
shriman_deepak
Prince Of Persia
shriman_deepak
Prince Of Persia
shriman_deepak
yes
Prince Of Persia
shriman_deepak
Prince Of Persia
shriman_deepak
Prince Of Persia
Prince Of Persia
Then tell me what's the output
shriman_deepak
a
shriman_deepak
Anonymous
I would ask if they are free sources code for html and css projects without javascript??
Prince Of Persia
Prince Of Persia
a
are you sure?
mine shows c
Prince Of Persia
I have tested that
shriman_deepak
#include<stdio.h>
int strleng(char str[])
{
int i = 0;
while (str[i] != '\0')
{
i++;
}
return i;
}
int main()
{
char str[100];
gets(str);
int n = strleng(str);
int max = n;
char ch;
for (int i = 0; i < n; i++)
{
int cnt = 1;
for (int j = i+1; j < n ; j++)
{
if (str[i] == str[j])
{
cnt = cnt + 1;
}
}
if (cnt < max)
{
max = cnt;
ch = str[i];
}
}
printf("%c",ch);
return 0;
}
Prince Of Persia
shriman_deepak
ah yes
shriman_deepak
= sign
shriman_deepak
But still this solution is not giving the correct output
Anonymous
#Question
I have a class like this:
Matrix Matrix :: operator * (double lambda)
{
...
return Matrix (aux_data, number_lines, number_columns);
}
The Matrix class also has a move constructor as follows:
Matrix :: Matrix (const Matrix && rhs)
{
number_columns = rhs.number_columns;
number_lines = rhs.number_lines;
data = rhs.data;
}
My question is, because I put the output of the * function in the Matrix, after moving and creating a new object, an extra copy happens so that the object reaches the caller?
I mean, should I not set the output type of the function * to type & Matrix?
Anonymous
Hello friends, what is the problem with the following code?👇👇👇
#include <iostream>
using namespace std;
int main()
{
int n; cin >> n;
long sum = 0;
int a;
long f = 1;
for (int i = 0; i < n; i++)
{
cin >> a;
f = 1;
for (int j = 2; j <= a; j++)
{
f *= j;
}
sum += f;
}
cout << sum;
return 0;
}
Pavel
Yeah after typing y it finishes the program
Not sure but it might be that something left from scanf (a newline character) and you read this first.
Here are some examples what you can try
https://stackoverflow.com/questions/12653884/getchar-does-not-stop-when-using-scanf
Also, you can print the value of ch to the console (e.g. in quotation marks, something like "\"%c\"") at the end of the loop to see what is in there. Or better yet use a proper debugger tool to break into/execute the code line by line and investigate the values.
Gaurav (a.k.a Avenger)
Anonymous
Hello
Anonymous
2pm wipro help text m
klimi
NagaRaju
Hello everyone,
I am trying to insert data into database using specific variables(like user given values).
This is my code :
#include <iostream>
#include <mariadb/mysql.h>
#include <cstring>
#include <sstream>
using namespace std;
void signUp (MYSQL* con, string name, string email, string password, int age, int weight) {
int id = 3;
stringstream ss;
ss << "INSERT INTO Users(User_id, Name, Email, Password, Age, Weight) VALUES ('"+id+"', '"+name+"', '"+email+"', '"+password+"', '"+age+"', '"+weight+"');";
string queryBuffer = ss.str();
const char* query = queryBuffer.c_str();
if (mysql_query (con, query)) {
cout << "SQL QUERY ERROR : " << mysql_error (con) << endl;
}
else {
cout << endl << endl << " YOUR DETAILS ARE SUCCESSFULLY STORED INTO DATABASE!" << endl;
cout << " Kindly login to experience the Application" << endl;
}
}
int main () {
MYSQL* con;
con = mysql_init (NULL);
// On success mysql_real_connect () returns ==> 1
if (!(mysql_real_connect(con, "localhost", "u0_a259", "", "Diet_db", 0, NULL, 0))) {
cout << "SQL Connection Error: " << mysql_error (con) << endl;
}
signUp (con, "Govind", "govind@gmail.com", "pass", 19, 54);
return 0;
}
I am getting error while inserting into table in my database
$ clang++ signup.cpp -o a -L/../usr/include/mariadb/mysql -lmysqlclient && ./a
ERROR :
warning: adding 'int' to a string does not append to the string [-Wstring-plus-int]
ss << "INSERT INTO Users(User_id, Name, Email, Password, Age, Weight) VALUES ('"+id+"', '"+name+"', '"+email+"', '"+password+"', '"+age+"', '"+weight+"');";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
signup.cpp:22:85: note: use array indexing to silence this warning
ss << "INSERT INTO Users(User_id, Name, Email, Password, Age, Weight) VALUES ('"+id+"', '"+name+"', '"+email+"', '"+password+"', '"+age+"', '"+weight+"');";
^
& [ ]
signup.cpp:22:88: error: invalid operands to binary expression ('const char *' and 'const char [5]')
ss << "INSERT INTO Users(User_id, Name, Email, Password, Age, Weight) VALUES ('"+id+"', '"+name+"', '"+email+"', '"+password+"', '"+age+"', '"+weight+"');";
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
amran
Hii hello. I'm new in this group. I wanted to ask. I want to create an app. But I don't have any knowledge about the programming. So than I need to hire app developer to create the app. Full stack developer or front end developer?. And how much it will cost me. Please guys do give advice. I will be really2 appreciate it
James
moni
// Please help why its not working
// Question is search element in rotated array
#include <iostream>
using namespace std;
int pivotElement(int array[], int size)
{
int s = 0, e = size - 1, mid;
while (s < e)
{
mid = (s + e) / 2;
if (array[0] <= array[mid])
{
s = mid + 1;
}
else
{
e = mid;
}
}
return s;
}
int binarySearch(int arr[], int key, int start, int end)
{
int s = start, e = end;
int mid;
while (s <= e)
{
mid = (s + e) / 2;
if (key == arr[mid])
{
return mid;
}
else if (key < arr[mid])
{
e = mid - 1;
}
else if (key > mid)
{
s = mid + 1;
}
}
return -1;
}
int searchInArray(int array[], int size, int key)
{
int getPivote = pivotElement(array, size);
if (key >= array[getPivote] && key <= array[size-1])
{
cout << "hi";
return binarySearch(array, key, /*s*/ getPivote, /*e*/ size-1);
}
else
{
cout << "byy";
/* code will write aftre some time*/
}
}
int main()
{
int array[5] = {7, 9, 1, 2, 3};
int key = 3;
cout << searchInArray(array, 5, key);
return 0;
}
moni
// Please help why its not working
// Question is search element in rotated array
#include <iostream>
using namespace std;
int pivotElement(int array[], int size)
{
int s = 0, e = size - 1, mid;
while (s < e)
{
mid = (s + e) / 2;
if (array[0] <= array[mid])
{
s = mid + 1;
}
else
{
e = mid;
}
}
return s;
}
int binarySearch(int arr[], int key, int start, int end)
{
int s = start, e = end;
int mid;
while (s <= e)
{
mid = (s + e) / 2;
if (key == arr[mid])
{
return mid;
}
else if (key < arr[mid])
{
e = mid - 1;
}
else if (key > mid)
{
s = mid + 1;
}
}
return -1;
}
int searchInArray(int array[], int size, int key)
{
int getPivote = pivotElement(array, size);
if (key >= array[getPivote] && key <= array[size-1])
{
cout << "hi";
return binarySearch(array, key, /*s*/ getPivote, /*e*/ size-1);
}
else
{
cout << "byy";
/* code will write aftre some time*/
}
}
int main()
{
int array[5] = {7, 9, 1, 2, 3};
int key = 3;
cout << searchInArray(array, 5, key);
return 0;
}
Anonymous
opengl
#include <GLFW/glfw3.h>
if (!glfwInit()) fprintf(stderr,"Error \n");
compile success
runtime : fprintf output
hardware ryzen
os ubuntu wsl
moni
what
as
#include <stdio.h>
#include <string.h>
int main() {
int key;
printf("no: ");
scanf("%d ", &key);
printf("no2: ");
char string[20];
fgets(string, 20, stdin);
printf("The String is %s\n", string);
return 0;
}
as
what is wrong?
Maksim
what do you want?
Maksim
as
as
i cannot write "no2: "