FAQ Database Discussion Community


Segmentation fault in 2D array unsigned char using calloc in C

c,arrays,char,unsigned,calloc
I've trying to allocate an unsigned char** using calloc: newmatriz = (unsigned char**) calloc(width, sizeof(unsigned char)); for (j=0 ; j < width; j++) { if (newmatriz[j]=(unsigned char*)calloc(witdh, sizeof(unsigned char)) == NULL){ printf("Memory allocation error. Exit program\n"); exit(1); } } for (i=0;i<width;i++) { for(j=0;j<width;j++) { newmatriz[i][j] = 0; } } But...

Restrict write of specific char on specific place c#

c#,winforms,char
I made a textbox for user input which receives text and converts it to double. I don't want to allow the user to crash my program, but also I want to know how can I do that instead of try catch. Input is positive or negative double. For now I...

[ performance]— string::operator+= vs. vector push_back

c++,string,gcc,vector,char
I was testing the performance between these two operations, and on G++ 4.7.3, the string::operator+= version is about 2 times faster. My simple test: What can be the cause of such a big difference? g++ -O2 --std=c++11 #include <iostream> #include <ctime> #include <string> #include <vector> using namespace std; class Timer...

change ascii code and preappend character to string in C++

c++,string,char
I want to pre-append a character to a string after performing some calculations to the character ascii code but doing (somenumber+'0') + s doesn't work and I don't understand why. the answer I want is "ahello" using the ascii representation of a ('0' + 49) This is what I have...

How to compare pointer and integer? [duplicate]

c,pointers,char
This question already has an answer here: How do I properly compare strings in C? 3 answers I'm trying to check if pointer is pointing at some char. Like this: #include<stdio.h> #include<string.h> #define a 3 int func(char *); int main() { char *s="a"; int type; type=func(s); printf("%d",type); return 0;...

Best way to store the first and second word of a text file into two arrays

c,arrays,char,fopen,fscanf
I'm making a code for a program. It would have three text files: -list1.txt having a column of words like: Cat Dog Fish Computers -change.txt having two columns of text like Dog Marbles Computers Store -list2.txt being empty The program would take list.txt, and store its words in the list2.txt,...

get const char from nsdictionary

ios,objective-c,char,nsdictionary
I am trying to read const char * from an nsdictionary so far I have tried NSLog(@"input1 %s",(const char*)inInputData); NSMutableDictionary * myDict = [[NSMutableDictionary alloc] init]; NSValue* inputData = [NSValue value:&inInputData withObjCType:@encode(const char)]; [myDict setObject:inputData forKey:@"inInputData"]; NSValue* readVal= [NSValue value:[myDict valueForKey:@"inInputData"] withObjCType:@encode(const char)]; NSLog(@"input2 %@",[myDict valueForKey:@"inInputData"]); NSLog(@"readVal1 %s",(const char*)readVal); NSLog(@"readVal2...

printing unique char and their occurrance

java,arrays,char
I am new to java and programming too. I have given an assignment to count the occurrence of unique character. I have to use only array. I have do the flowing code - public class InsertChar{ public static void main(String[] args){ int[] charArray = new int[1000]; char[] testCharArray = {'a',...

C++ Using function with sprintf_s inside sprintf_s

c++,char,buffer
I want to write data into a char buffer. Therefore I have a function to format my data. As an example, I just pass an int value to the function like this: using namespace std; #include <iostream> char* writeData(int iData, char* sBufferData){ sprintf_s(sBufferData, 2048, "val:%i", iData); return sBufferData; } int...

Print each word in a separate line from an input string

c,string,char,printf,scanf
I'm having trouble printing each word in a separate line from an input string in C. The question from the assignment I'm doing states: Take a sentence as input and print its words in separate lines. My Code: #include<stdio.h> int main() { int i; char s[100]; scanf("%s", s); for(i=0; s[i]!='\0';...

C memory allocations

c,arrays,memory,char
I was wondering how the C compiler allocated memory for a character array you initialize yourself, for instance: char example[] = "An example string"; If it was a single character it would be 8 byte, so would the example be 17 bytes or does it have more because it needs...

Why is my char printing as a number instead of a character?

java,char,int
As per the Java ternary operator expression ? statement1 : statement2, if expression is true then statement1 will be executed, if expression is false then statement2 will be executed. But when I run: // some unnecessary codes not displaying char y = 'y'; int i = 0; System.out.print(false ? i...

Concatenate plain char and string?

c++,string,char,concatenation
im getting totally confused by this seemingly simple problem. I have a pain old char, and I want to concatenate it in the middle of a string. Like so. string missingOptionArg(char missingArg) { return "Option -" + missingArg + " requires an operand"; } I was guessing the + operand...

“initialization makes integer from pointer without a cast” waning in array initialization

c,arrays,pointers,char,compiler-warnings
I am now starting to learn C. I would like to know why I get the warning. I declared a bidimensional char array, but why the character "d" is not allowed? char array[3][3] = {{1,"d",3},{3,2,1},{2,1,3}}; ...

code gives out ASCII numbers instead of characters

c++,char,ascii,red-black-tree
This code is part of a RedBlack Tree program supposed to receive "ADSOMERT" and sort its characters into Inorder form "A D E M O R S T". It does the job, but with the ASCII numbers of each character "65 68 69 77 79 82 83 84". Main function:...

segmentation fault while calling strlen with a previously allocated pointer

c,pointers,char,segmentation-fault,strlen
Up until now I have had some code that worked perfectly regarding a variable called wfiles. wfiles is initialized within my main file: char* wfiles = ""; Which as far as I can tell C has no complaints. Next the wfiles variable is allocated in a switch statement: switch (c)...

Cant find resolution for the error “invalid conversion from char to const char*”

c++,string,char,border,const
I have looked around but cant find an answer to my question. The program is suppose to put a border of stars (*) around a heading, but I'm getting the error: invalid conversion from 'char' to 'const char*' [-fpermissive] as well as the error initializing argument 1 of 'std::basic_string<_CharT, _Traits,...

How do I identify the last variable argument? [duplicate]

c++,char,arguments,printf,va-arg
This question already has an answer here: Count number of parameters in C variable argument method call 3 answers So in my function I want to take a variable number of char pointers. void myFunction(char *_Name, ...); Only, when I iterate through the arguments my code breaks because I'm...

Wrong filename when using chinese characters

c++,string,character-encoding,char
I'm trying to create a file on Windows using a Chinese character. The entire path is inside the variable "std::string originalPath", however, I have a charset problem that I simply cannot understand to overcome. I have written the following code: #include <iostream> #include <boost/locale.hpp> #include <boost/filesystem/fstream.hpp> #include <windows.h> int main(...

counting characters in the input with while loop

c,loops,while-loop,char,eof
I wrote a simple c program to count number of characters #include <stdio.h> main() { long nc; nc = 0; while (getchar() != EOF) ++nc; printf("%ld\n", nc); } This program is not printing me the characters. On testing different cases, I found that I am stuck in an infinite while()...

char* string substract function throws exception

c++,arrays,string,char
I'm working on my own string class called PString, I have this function that finds a specific character, like 6, and now I have this function called substr short fo substract, where I want to substract from 0 to [insertnumber]. the way I'm trying to call this is by doing...

C program skips a line when asking for user input [duplicate]

c,char,user-input,scanf
This question already has an answer here: C: Multiple scanf's, when I enter in a value for one scanf it skips the second scanf 6 answers printf("Number of tracks: "); fflush( stdin ); scanf("%d", &track); printf("Is this an album or single: "); fflush( stdin ); scanf("%c", &type); when I...

Deleting dynamic char** in C++

c++,arrays,dynamic,delete,char
Disclosure: Hi, I'm trying to solve a challenge with strict time and memory limits. I would normally use vectors and strings, but here I need the fastest and smallest solution (with vectors it actually ran above the time limit), so I turned to dynamic arrays of char*. The relevant parts...

Android Studio get char code

android,char,zxing
In ZXing return I have code: result.getContents().substring(0, 1) And I would like get first char and return his char-code. The geting first char work correctly, but I don't found code to change char to char code. Any Ideas?...

C# Replace Cyrillic chars failed

c#,string,char
I need replace Cyrillic chars to be transliterated Latin chars. Unfortunately my solution always return -1 when search for char position. What's wrong with that? StringBuilder sb = new StringBuilder(); var domain = ConfigurationManager.AppSettings["Domain"]; catname = catname.ToLower(); var englishchars = new string[] { "a", "b", "v", "g", "d", "e", "yo",...

How to get a char sequence from String that contains a searched string

java,string,char,contains
I would like to know if their is a function in JAVA that allows to retrieve from a huge string a char sequence that contains a special char. Example: I have a php page that that I've stringified and I check if there is a char sequence containing the char...

F# - What is the best way to convert a char[] to a string?

arrays,string,f#,char
Is there an easy way to convert a char[] to string in F# without explicitly looping over the array? I tried: let char_arr = [|'a','b','c'|] let str = new String(char_arr) but that doesn't work. Suggestions?...

Convert a String to binary sequence in C# with zero padding when not 8 bits of char

c#,string,character-encoding,char,ascii
I use this method which I saw in one of the questions to convert ascii to binary string: public string GetBits(string input) { StringBuilder sb = new StringBuilder(); foreach (byte b in ASCIIEncoding.UTF8.GetBytes(input)) { sb.Append(Convert.ToString(b, 2)); } return sb.ToString(); } But, If the input is something like the message bellow...

C - delete vowels in a string

c,string,function,char,vowel
I want to write a program that deletes the vowels in a string. This is my code so far: #include <stdio.h> #include <string.h> void f (char s[100]) { int ok=0; for (int i=0; i<strlen(s); i++) { if ((s[i]=='a')||(s[i]=='e')||(s[i]=='i')||(s[i]=='o')||(s[i]=='u')) { ok++; strcpy (s+i,s+i+1); } } printf ("%s",s); } int main ()...

Why char is of 1 byte in C lanaguage

java,c,char,language-lawyer
Why char is of 1 byte in C? Why it's not of 2 bytes or 4 bytes? What is the basic logic behind it to kept it in 1 byte? I know in Java it's of 2 bytes. Same question for it....

Difference between char array declaration forms

c,arrays,string,char
we had this question in programming exam, and we are all debating the correct answer, soo what do you think? 3.1 Which of the following is an incorrect string initialization? (a) char plant[] = "Tree"; (b) char plant[] = {'T','R','E','E'}; (c) char plant[80] = "Tree"; (d) char plant[80] = {'T','R','E','E'};...

Pass vector of char vectors to char**

c++,vector,stl,char
Is it possible to pass a std::vector<std::vector<char>> to a function void doSomething(char** arr) e.g. to store a bunch of paths similar as with std::vector<char> vec to void func(char *str) vec.assign(64, ' '); Function call: func(vec.data());...

Conversion from char to int and printing the decimal value

c,char,printf,decimal,ascii
char str[20]; printf("Enter anything\n"); scanf("%s",str); for(int i = 0 ; i<strlen(str) ; i++) { if( isdigit(str[i])) printf("%d",(int)str[i]); } I tried with the above code but the output is in ASCII values of the numbers rather then actual numbers. Like , input: "0" output: "48". When I try (int)(str[i]-'0'); instead of...

convert list that represent binary string into ASCII C#

c#,list,char,ascii
I have a list of chars that represents a binary string. List<char> myCharList = new List<char>(); For example, the charList holds the ascii H which represented by the binary sequence: 01001000 I try to convert this List into ASCII so I can show it in a Text Block. Thanks ...

Custom String Deficiency

c++,string,char,comparison
So my problem currently is when I do a comparison with a modified string value, and a string value that has not been modified, I do not get the expected result of true, but a false. I have overloaded the logical comparison operator, but that's not what I want to...

Printing an array of characters with “while”

c,string,char,null-terminated
So here is the working version: #include <stdio.h> int main(int argc, char const *argv[]) { char myText[] = "hello world\n"; int counter = 0; while(myText[counter]) { printf("%c", myText[counter]); counter++; } } and in action: Korays-MacBook-Pro:~ koraytugay$ gcc koray.c Korays-MacBook-Pro:~ koraytugay$ ./a.out hello world My question is, why is this code...

ifstream no conversion from char to char exists error

c++,char,ifstream,getline,c-strings
int main() { char buffer[1024]; ifstream dataFile ("./data.dat"); while(buffer) { localHouse->location = dataFile.getline(buffer, 1024); } } This throws the error: No suitable converion function from "std::basic_istream<char, std::char_traits<char>>" to "char" exists. It continues to throw this error if I use a pointer to buffer instead. as far as I can...

Copy vector into char*

c++,vector,char,c-strings
I'm just studying C and C++ programming. I've searched and can't seem to find an answer that has a decent response. Of course using <string> is much easier but for this task I am REQUIRED to use only clib <string.h> functions; I'm also not allowed to use C++11 functions. I...

Why can I generate char beyond max value?

java,char
Why does the following code not generate an error? System.out.println((char) 2147483647); According to oracle datatypes, the maximum size for a char is 65,535. char: The char data type is a single 16-bit Unicode character. It has a minimum value of '\u0000' (or 0) and a maximum value of '\uffff' (or...

Remove all characters between 2 characters in a String

java,string,char,between,removeall
I have a database with 50000 rows. I want to get all rows one by one, put them into a String variable and delete all characters between "(" and ")", then update the row. I just don't know how to delete all characters between "(" and ")". I want to...

How do char and int work in C++

c++,char,integer,int
May be I'm going to ask a stupid question, but I want to confirm that how char works? Let me explain with examples what i want to ask. Let suppose I declare a char variable and then input 6 or any integer character. #include <iostream> using namespace std; int main(){...

How to store user input in an int array

c++,arrays,string,char
I need to ask the user to input 8 zip codes and then store them in an array of integers and then to output them one by one , each being in a new line.These two things should be done in separate functions. But when it runs the code first...

java string to char array and inverse leads to wrong result

java,string,char
I want to convert a String to a char [] to perform some bitwise operations on it. My first approach was to use the java standard functions: String foo = "123456789" char [] bar = foo.toCharArray(); System.out.println(bar.toString); //output: [[email protected] So it seems that the data gets altered using this function....

Cannot print char array from stdin in c

c,char
I am trying to read in from stdin and then print each char from each string but it will not print anything for some reason... #include <stdio.h> #include <string.h> int main(void){ int i; char string[10]; while (fgets(string,10,stdin)!=NULL){ for(i=0;i<strlen(string);i++);{ printf("%c",string[i]); } strcpy(string,""); } return 0; } ...

Convert char to float in c

c,floating-point,char,type-conversion
I need to convert char to float. I know we can do this with the help of atof() function. But I dont want to create another variable to hold the float. I want the converted float to go in the same variable. Like this operand = atof(operand) Here operand is...

Find words divided by whitespace

c,arrays,char,fgets
Is it possible to use fgets() to save different words divided by whitespace and then find each word? For example let's say I have this: char words[100]; fgets(words,100,stdin); and then I have to find each word to use it in the rest of my program. How can I do that?...

How to split string in chars and get code of each char in freemarker?

casting,char,freemarker
I think that I can split using this: <#list str as c> ... </#list> But then I need to convert this char to byte and add it to another number. In most languages it will be like so: int num=53, res; char c='g'; res=num+c;//c cast to byte and then to...

c# remove duplicate char from array

c#,arrays,string,char
static string RemoveDuplicateChars(string key) { // --- Removes duplicate chars using string concats. --- // Store encountered letters in this string. string table = ""; // Store the result in this string. string result = ""; // Loop over each character. foreach (char value in key) { // See if...

scanf get multiple values at once

c,char,segmentation-fault,user-input,scanf
I need to get in one single shot different inputs from one single line. In particular I need to get a single char and then, depending on which char value I just read, it can be a string and an int or a string, an int and another string and...

Convert wide CString to char*

c++,mfc,char
There are lots of times this question has been asked and as many answers - none of which work for me and, it seems, many others. The question is about wide CStrings and 8bit chars under MFC. We all want an answer that will work in ALL cases, not a...

Checking character arrays - returns same answer each time

c++,arrays,char
So I've been programming for an assignment -- I am supposed to create a program that asks for the number of questions, the correct answers, and the answers provided to score the test.In the program I wrote, I always get the same return value for the score: 4199676 Can anyone...

Sorting characters alphabetically in a String

java,arrays,string,sorting,char
Could smb please explaing the process of sorting characters of String alphabetically? For example, if I have String "hello" the output should be "ehllo" but my code is doing it wrong. public static void main(String[] args) { String result = ""; Scanner kbd = new Scanner(System.in); String input = kbd.nextLine();...

Get part of a string with dynamic length in C

c,string,char
I got the following string from the user: char *abc = "a234bc567d"; but all the numbers can have different lengths than in this example (letters are constants). How can I get each part of numbers? (again, it can be 234 or 23743 or something else..) I tried to use strchr...

how I get a number outside [0,255] when doing a converson from int to char?

c++,char,type-conversion
I do not see why conversion from int to char gives me a number outside the range of (char)? Here is my C++ program: #include <cmath> #include <stdio.h> int main(){ printf("%c\n",(char) 246 ); printf("%d\n", (char) (246) ); } I get \366 -10 Any explanation? What I need here is a...

C++ Expression Must Have Class Type - String to const char*

c++,.net,string,char
Trying to convert string to const char* gives "expression must have class type" at the bottom line. Tried some variations on converting with no luck. any ideas? string GetMachineID() { // LPCTSTR szHD = "C:\\"; // ERROR string ss; ss = "Err_StringIsNull"; UCHAR szFileSys[255], szVolNameBuff[255]; DWORD dwSerial; DWORD dwMFL; DWORD...

Comparing char array elements

c,arrays,sorting,char,bubble-sort
I'm trying to arrange this character array that only contains digits,it prints the same array with the order I input it without any change , i tried using type casting in the if statement, it gave me correct results when running but it wasn't accepted by the online judge.what is...

I made a for loop to swap two indiv char variables in a string

java,string,random,char,swap
I am supposed to write a method that scrambles a word, switching two letters in a word that is not the first or last character. I've initialized i and j as random integers between positions 1 and str.length() -1. Is there a reason why this loop would not print the...

What is the difference between UTF-32 and UCS-4?

string,unicode,encoding,char,utf
What is the difference between UTF-32 and UCS-4 ? Isn't UTF-32 supposed to be a fixed-width encoding ?

Fill value by value a char *

c,list,pointers,struct,char
I'm trying to fill a char *info inside a struct nodo; This is struct : struct nodo { char *info; struct nodo *prec; struct nodo *succ; }; typedef struct nodo nodo; And this is whole function : nodo *q,*t = NULL,*head = NULL; int i, nodi=0 ; char *c =...

Increase the maximum size of char array

c,arrays,char,size,max
I have written some code in C by taking the maximum size of char array as 100. It worked well. But when I increase the maximum size of char array to 10000 it gives me segmentation fault(as it has exceeded its limit). Can someone tell me how can I increase...

C: using fgets() to read from file

c,char,fgets
I currently have this> FILE *in=fopen("some_file.txt", "r"); char input[3]; int i=0, j=0; if(in!=NULL) { fgets(input, sizeof(input), in); initialize(input); } while(j<100) { fgets(input, sizeof(input), in); addNode(head,input); j++; } fclose(in); display(); I think I have a problem with fgets(). In my mind, three chars are> input[0] = some char, input[1] = '\0',...

Calculating Gematrical Value of a String in C# without Using a Dictionary

c#,dictionary,char
The code below attempts to calculate the gematrical value of a string: for (int i = 0; i < str.Length; i++){ switch(str[i].ToString()){ case "A": gemValue += 1; break; case "a": gemValue += 1; break; case "B": gemValue += 2; break; case "b": gemValue += 2; break; // other characters to...

How to draw a rectangle using a char parameter in C++?

c++,parameters,char,drawing
I want to draw and fill a rectangle using C++. The function parameter passed in must be a char, not an int. In my header file the drawing function is this: void draw(char); My rectangle.cpp file is this: void rectangle::draw(char ) { for(height=0;height<=height;height++) { for(width=1;width<=width;width++) { cout<<'*'; } } }...

converted string failed to contain correct values of float

c,pointers,char
I am facing problem in converting float to char*. I have written a function that will put integer part of float in string and then decimal values. I need it for two places of decimal. But something is horribly wrong. Either it ouputs integer value or just 1 place after...

C++ error: deduced conflicting types for parameter 'T' string vs const char *

c++,string,templates,c++11,char
So, I am writing a simple, templated search function for deque container. Here's the code: template <typename T> void searchInDequeFor(std::deque<T> Deque, T searchValue) { for(const auto & element : Deque) { if(Deque.empty()) { std::cout << "Deque is empty, nothing to search for..." << "\n"; } else if(element==searchValue) { std::cout <<...

How to allocate memory dynamically for a char array in C++?

c++,arrays,pointers,char,dynamic-memory-allocation
I am learning about dynamic memory in C++. What I learned as a standard way of allocating & deallocating dynamically for any data type is, for example, //For double, double* pvalue1 = nullptr; pvalue1 = new double; *pvalue1 = 17.3; delete pvalue1; //free up when I'm done BUT, for a...

Why char[] work,but char * doesn't [duplicate]

c,char
This question already has an answer here: Why do I get a segmentation fault when writing to a string initialized with “char *s” but not “char s[]”? 18 answers code1: int main() { char tmp[20] = "1.04"; printf("float str is %s\n",tmp); delcharPoint(tmp); printf("%s\n",tmp); } void delcharPoint(char *pStr) { char...

Global character array won't be reassigned or outputted correctly

c++,arrays,char,global
I'm trying to make a very basic tic tac toe program, and I'm storing the board in a character array. The array is global so I can output it from a function and also assign X's and O's to places in the main function. My code is below. The problem...

getchar() not working in c

c,while-loop,char,scanf,getchar
getchar() is not working in the below program, can anyone help me to solve this out. I tried scanf() function in place of getchar() then also it is not working. I am not able to figure out the root cause of the issue, can anyone please help me. #include<stdio.h> int...

Copy an Array of Characters into a Pointer of characters

c,arrays,pointers,char
I am trying to copy a char[] array into a char* pointer. I have 2 datatypes: CHAR* dst and CHAR src[] My goal is to perform this operation without using any C++ definitions such as new or delete. As you may understand, this means that I am looking for an...

Store int in 2 chars

c,casting,char,int
Quick question: Since int is 2 bytes and char is 1 byte, I want to store an int variable in 2 char variables. (like bit 1 - 8 into the first char, bit 9-16 into second char). Using C as programming language. How can I achieve that? Will something like:...

Remove duplicates numbers above 10 in a String [duplicate]

java,string,char,duplicates
This question already has an answer here: How to efficiently remove duplicates from an array 16 answers I made a program that removes duplicates of characters in a String when pressing a button. So for example if the String is "23332" the output is "23". Now my problem is...

How to change the character count result of a PHP query?

php,count,char,hide
I have created or implemented this character limiter which is common on many websites, in my case I set the limit to be 200 characters at most to be shown followed by an ellipsis. $str = $row[1]; $count = strlen($str); if($count<200){ $post = $row[1]; }else{ $end = $count-200; $mod =...

C++ No viable conversion from string to const char * [duplicate]

c++,string,char
This question already has an answer here: How to convert a std::string to const char* or char*? 6 answers I'm using C++ (using CERN's ROOT framework) and I'm having a little problem with strings. I'm trying to label a histogram axis using a string defined by the user earlier...

Determine the ranges of char by direct computation in C89 (do not use limits.h)

c,char
I am trying to solve the Ex 2-1 of K&R's C book. The exercise asks to, among others, determine the ranges of char by direct computation (rather than printing the values directly from the limits.h). Any idea on how this should be done nicely?

Working with chars and only solution I've found is to static_cast twice. Is there a way around this?

c++,char
This code seems a bit ridiculous, but it's the only way I found to deal with my problem... char word[10]; cout << std::hex << static_cast<int>(static_cast<unsigned char>(word[i])); This is my way of cout-ing a char as a hex value (including signed chars). It seems to work great (to my knowledge), but...

C++ Make a Char Array have a Value of the string

c++,arrays,class,char
For my program, I have a highscore section. I get the input with a string, but how can I now make the string equal into a char array? FYI: The string playersName will already be filled out with a name. Here is my code: class Highscore { public: char name[10];...

How do would I alphabetize the strings in my character array?

c,arrays,char,words
I've written a program to count the occurrences of letters and words from a string that the user enters. I have successfully gotten most of it to work now, however, I must also alphabetize the words I have stored in my array of pointers. I saw a function void sortstring()...

Swap and Return Char Array from the Function

c++,arrays,reference,char,swap
I know there are many questions related to my this question but still facing problem. I'm using the function to swap array mean when I input ABCD it shoudl return DCBA. Code is below check where is problem. Is there a way to pass second empty array as reference? Swap...

Using Special Characters in Java (using primitive char)

java,arrays,char,special-characters,primitive
I'm basically trying to build a random password generator in Java. I'm trying to build it using a char array, basically: char[] password = new char[8] I want to be able to include "special" characters in this array (such as @, $, *, etc). Can these characters be placed in...

Remove specified char from strings in C

c,string,char
I am making a program that will search in an array of strings, and for each string, it will search for a specified char. If it finds that char, remove it. In this example I want to remove the character 'r'. Here is the code: void convertStrings(char **line) { for...

strcpy copies content of an other array

c++,arrays,string,char
So I have this piece of code to convert a char array to the contents of a struct. (no, I'm not gonna argue on whether or not this is the right/most efficient way to do it) void chararray_to_categorie(categorie &levarr, char** chararray) { string temp = chararray[0]; int length = temp.length();...

Why isn't the first character uppercase?

java,string,char,uppercase,lowercase
I have found syntax that is supposed to change the first character from a lowercase letter to an uppercase letter. For some reason my program won't! When I type a 'm' instead of 'M'. What am I doing wrong here? public static void main(String[] args) { System.out.print("Enter two characters: ");...

`Cannot convert 'char(*)[50]' to 'char**' for argument '1' to 'void prac(char**)'` when passing a 2D array to a function [duplicate]

c++,function,char,argument-passing
This question already has an answer here: Correct way of passing 2 dimensional array into a function 6 answers I wanna pass 2D char array to function. However, an error comes: Cannot convert 'char(*)[50]' to 'char**' for argument '1' to 'void prac(char**)' How can I fix the code ?...

Why am I getting the opposite of what is true in List.Contains(char)

c#,linq,list,char,utf
I have tested this in two applications; Where I pass in a char looking for a special character. static void Main(string[] args) { ConsoleKeyInfo entered = Console.ReadKey(); char asChar = Convert.ToChar(entered.KeyChar); Console.WriteLine(IsSpecialChar(asChar)); Console.ReadKey(); } private static string IsSpecialChar(char dWord) { List<char> Special = new List<char>(); System.Globalization.NumberStyles hexer = System.Globalization.NumberStyles.HexNumber; Special.AddRange(Enumerable.Range((int.Parse("21",...

Java Char Empty Character Detection

java,char
Right so im using java on eclipse and kept coming up with a problem. What im trying to fix is when the user is promoted to press any key. When the key is enter and no Char the program collapses due to it can't find a character. my code is:...

Counting paragraphs that dont end in a Period, C Language

c,file,char
Basically i need to find a way to discover if the paragraph ends or not in a Period (.). At this moment i can already count the paragraphs that the given text has, but im not coming up with anything to check if it ends or not in a Period....

C++ Templates specialisation char* and Valgrind

c++,templates,memory-leaks,char,valgrind
I've got a huge problem with memory leaks in my program. I use Valgrind to check memory leaks and with some changes I got about ~20 errors or ~40 errors, but still I can't eliminate all and don't know how. And I can't change the code in main function, I...

C convert const char * to char

c,string,pointers,char,switch-statement
I searched quite a while to find the answer, but I could only find a solution for C++ that didn't seem to work for C. I'm trying to convert argument of const char * to char to use in my switch statement. I tried various things like strdup(), but was...

how to convert bool array to char variable

c#,char,boolean,type-conversion
I have a boolean array which holds some values that represent ASCII value: bool[] myBoolReceived = new bool[8]; I try to convert it to a char so I can add it to a list that holds chars. myReceivedMessage = new List<char>(); I tried to use Convert.ToChar method but it not...

Working with malloc, char array and pointer

c++,arrays,pointers,char,malloc
I'm trying to understand how malloc and characters arrays(c style) work. Consider the following code, // Example program #include <iostream> #include <cstdlib> #include <iomanip> using namespace std; int main() { //section1: Init char line0[10] = {'a','b','c','d','e','f','g','h','i','j'}; char line1[10] = {'z','y','x','w','v','u','t','s','r','q'}; //section2: Allocate Character array char* charBuffer = (char*) malloc(sizeof(char)*10); cout<<sizeof(charBuffer)<<endl;...

Two dimensional dynamic char array cpp

c++,arrays,pointers,char
I need to create global n fields of 20 characters in c++ 11 as simple as possible. #include <iostream> using namespace std; char(*a)[20]; int main(){ int n; do{ cout << "N= "; cin >> n; } while (n<1); a[20] = new char[n][20]; for (int i = 0; i<n; i++) cout...

How to realloc a *char[] inside a while loop?

c,pointers,char,malloc,realloc
Let's consider this array of char pointers : char *lesMots[10]; Which is used inside a while loop : while(fgets(buffer, TAILLE_BUFFER, fichier)!=NULL){ token = strtok(buffer, s); while( token != NULL && token[0]!=13) { token[strlen(token)]='\0'; *(lesMots + ligne)=strdup(token); ligne++; token = strtok(NULL, s); } } I'm trying to reallocate the memory of...

Program to reverse a string in C without declaring a char[]

c,string,pointers,char
I need to reverse a given string and display it without using the value At[index] notation , I tried the below program using pointers,but it does not print anything for the reverse string, Please help! int main() { char* name=malloc(256); printf("\nEnter string\n"); scanf("%s",name); printf("\nYou entered%s",name); int i,count; count=0; //find the...

Char to Int - C++

c++,list,struct,char,int
I know there are already answered questions about it, but I have read most of them and still couldn't solve my problem. I have a program that will read notes, keep them in a list and give options to the user to delete, change, or select a specific note. I'm...

Char Comparison in Common Lisp

sorting,char,comparison,lisp,common-lisp
How can i compare characters with Common Lisp? I have google it and found out that there are some functions to do the comparison, like char=, char/=, char<, char>, char<=, and char>=. But, i can't use all of the functions just like: (char= 'a 'a) (char< 'a 'b) If i...

Both null and empty char are equal in java

java,database,null,char
I have doubt while taking a null or empty char check in Java. Is both have to be checked in any way. For example in database the variable length for Char is 1 . It will allow null as well. So if you have empty char does it mean null?...

Templates. adding , getting element char*

c++,templates,char,containers
I've got a problem with my template class and using it for char*. I storage elements in class and try to add or get element ,but segmentation fault appear. Is it possible without class specialisation for type char* ? Edit 1: Let's assume that I can't change the code in...

Adjacent character and string literal tokens

c,string,char,language-lawyer,c11
It's a familiar fact that in C you can write "a" "b" and get "ab". This is discussed in the C11 standard: In translation phase 6, the multibyte character sequences specified by any sequence of adjacent character and identically-prefixed string literal tokens are concatenated into a single multibyte character sequence....

Trailing zero as a result of snprintf

c,arrays,string,char,printf
Today I ran into a problem that I just can't get the hang of. Consider this code snippet: static const char *LOG_MESSAGES[] = {"String1.", "A longer string 2.", "String 3"}; Somewhere in the main() function, I wrote: printf("%s\n", LOG_MESSAGES[1]);//Prints "A longer string 2." as expected. char rawLog[100] = {0}; printf("%s\n",...