C :: Warning When Handling Pointer To Char
Apr 4, 2014
Here is my code. I am combining two words and sorting the merge word in alphbetical order. The compiler giving me warning error
Program:12:4: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat] Program:14:4: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[100]' [-Wformat]
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
[Code].....
View 3 Replies
ADVERTISEMENT
Jan 23, 2014
int hash = 0;
char *strings[100];
if((int)strings[i] != 0)
if((int) strings[hash] != 0)
while((int) strings[hash] != 0)
if((int)strings[hash] != 0)
if((int)strings[hash] != 0)
View 12 Replies
View Related
Apr 17, 2014
I'm working on a program and everything works except for the follow function:
void swapHex(int x, int byte1, int byte2) {
unsigned char *b1, *b2, tmpc;
printf("%d in hex is %x
", x, x);
printf("swapping byte %d with byte %d
", byte1, byte2);
[Code] ....
I get the following errors when compiling:
In function "swapHex":
warning: assignment from incompatible pointer type
warning: assignment from incompatible pointer type
View 2 Replies
View Related
Sep 21, 2013
I have a function that I want to exit gracefully when an "error" occurs in an input file. My function declaration is:
Code: BSTnode *buildTree(FILE *fp)
The few lines that are causing the problems are:
Code: if(regcomp(®ex, to_find, REG_EXTENDED | REG_NEWLINE) != 0) {
fprintf(stderr, "Failed to compile regex '%s'
", to_find);
return EXIT_FAILURE;
}
I know that if I just use "return" by itself the warning goes away but fails to exit when the error occurs. I also believe this may not be the correct use of stderr. But I need the program to exit when an error has occurred.
View 9 Replies
View Related
Jun 4, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
[Code].....
View 2 Replies
View Related
Jun 4, 2013
#include <stdio.h>
#include <stdlib.h>
int size_b_row1;
int size_b_col1;
int main(void) {
double C[4][4] = {{1,3,5,2},{7,6,2,2},{1,2,7,3},{2,3,5,3}};
double TC[4][4];
transpose(C, TC);
[Code] ......
View 2 Replies
View Related
Feb 3, 2013
I thought we needed to allocate memory before assigning a value to a char* and also that we needed to use functions like strcpy() to copy something into it. Then how come this works and does not crash?
Code:
#include <iostream>
using namespace std;
int main()
{
char * buf;
buf = "Hello";
cout << buf << endl;
buf = "World!!!!!!!!";
cout << buf << endl;
return 0;
}
View 3 Replies
View Related
Aug 31, 2013
I like to use a Pointer to char array. And then I would like to do a Pointer Arithmetic by incrementing the Pointer. Finally I would like to see the Addresses of the Pointer to each of the char Array Elements. I had created a program below, but I am not getting any Addresses from my Pointer.
#include <iostream>
using namespace std;
int main () {
int ArraySize;
char ch[]= "This is a Char Pointer";
char* iPtr = ch;
[Code] ....
View 3 Replies
View Related
May 4, 2013
#include <iostream>
using namespace std;
int replace(char *ptr, char c1, char c2);
int replace(char *ptr, char c1, char c2){
int count = 0;
int i = 0;
[Code] ......
Segmentation fault (core dumped)
View 5 Replies
View Related
Mar 24, 2015
I am trying to return a char pointer so that i can re use it again. I am writing a vigenere function that takes a message, a key and an initialization vector where it performs the encryption, prints out the encrypted message and returns the encrypted message. I print out the process step by step and everything works, however i pass the answer and print it out again and only the first letter gets changed. I put my code below and my output right after that.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
void decrypt(char *to_encrypt, char *key, char* pct);
enum flag{encryption = 1, decryption = 0};
[code].....
View 3 Replies
View Related
Jun 12, 2013
Is there a more simple method to copy Buf into str? Buf is a binary string.
Code:
void function(string & str) {
int iWholeSize = 512;
char * Buf = new char[iWholeSize];
.... operations on Buf
string s(Buf, Buf + iWholeSize);
str = s;
}
View 5 Replies
View Related
Jun 7, 2013
Alright, so I have a code that's not giving me errors, but it doesn't seem to retain what I put into an array. Not sure If I'm missing something...
Code:
#include <stdio.h>
int main (void)
{
const char *pointer;
const char alphabet[] = "ABCDEFG";
pointer = &alphabet[5];
printf("pointing to %c of the alphabet
", pointer);
return 0;
}
Trying to get my pointer to return the letter in the [5] spot or "F". Not receiving any errors when compiling, but I seem to get different answers every time I run it.
View 5 Replies
View Related
Jan 2, 2014
I'm having a problem understanding something with pointers. I was trying to pass a pointer into a function in MSVC-2013, like
char* charptr;
and then calling
myfunct(charptr);
and then inside the function i would set charptr equal to another char ptr, simply like
charptr = anothercharptr;
But this actually caused a compile failure in MSVC, saying charptr is being used without being initialized. in Code::Blocks it just gives buggy output.
I solved this issue by calling the function like
myfunct(&charptr);
and declaring the function like
myfunct(char**);
and then I had to dereference the charptr in the function when assigning it to another ptr, so
*charptr = anothercharptr;
It seems like you should be able to just pass a ptr into a function and change its address to that of another pointer? My main question is really, what is the value of a pointer? I thought the value of a pointer was just the memory address it contains. But then I had to reference it to pass it into the function.
What is the difference between the value of the char* charptr written as either charptr and &charptr?
View 1 Replies
View Related
Mar 5, 2013
Here's the code I'm working on:
string* arrayPush(string *array, char **toks){
if(array[sizeofHistory -1].empty()){
//find the next available element
for(int i=0; i < sizeofHistory; i++ ){
[Code] ....
toks is an array of pointers to strings. I need to assign a toks to array[i].
View 10 Replies
View Related
Feb 5, 2014
I am using a small robotic-car that is controlled by writing C/C++ codes under Linux. I need to use a particular function from the library provided by the manufacturer. The relevant API documentation for the function is:
BASEBOARD_ERROR_KIND ZMP zrc :: :: :: Baseboard GetRS232Data (char * msg )
RS232 data acquisition.
Argument:
[Out] msg Address of the acquired data.
Returns:
BASE_OK RS232 data acquisition success
BASE_BASE_232_GETDATA_ERR RS232 data acquisition failure
I have trouble writing the relevant code in the main program that invokes this function. Here is a snippet of what I have tried:
# include "Baseboard.h"
int main () {
Baseboard _Baseboard; // Class name is Baseboard
char *msg ;
[Code] ......
The part where I am uncertain is how to handle the char pointer "msg" in the declaration, function call and referencing. According to the documentation, the char pointer "msg" is the output of the function so I presume that is is somehow dynamically allocated. Am I handling the char pointer properly in the declaration, function call and referencing parts?
Another related question I have is: I am printing out the value of the variable "dummy". I always get 0 for it. Since the variable "dummy" is an enum of type BASEBOARD_ERROR_KIND which can take on two values (first value represents success and the second failure), it is alright to get a integer value of 0 for it if the function call was successful ? (I do not have much experience with using enums so this is a enum-related question on whether we can get an integer value representing the first enum value) .
View 2 Replies
View Related
Dec 9, 2013
I have a pointer to an Address is there a way to save that address value (not the content but the actual address) into a char ?
View 5 Replies
View Related
Sep 19, 2013
I understand you can do
char* charpointer[2];
charpointer = "12";
if (charpointer[0] == '1'){
}
but how can we test for a range? 0-1? so I can compare it to '12'
I wouldn't want to do charpointer[0] == '1' && charpointer[1] == '2' though.
View 1 Replies
View Related
Oct 6, 2014
how string literal that works with the cin object?
char * str = "This is a string constant";
Is the str stored the address of the first character of the string literal?
But some books just state that the pointer-to-char (char pointer) stores the address of the string literal". So just wonder how it is.
When it is used with cout, cout just treats it like a string and instead of printing the address, it just prints out all characters one by one until it reaches the terminated null character.
If this is the case, then I am just wondering how cin works with it? with a statement like this cin >> str; ?
Does the computer allocate enough memory for it? and then cin stores the first character into the first address and then advances to the next address and stores the next character?
View 1 Replies
View Related
Aug 10, 2013
I can assign values to pointer character array like this...
Code:
char *array[4]={"abc","xyz","dgf","sdt"} ;
but the case is i don't know how to assign strings through key board ???? with using gets ,getchar or other suitable function
View 2 Replies
View Related
Dec 2, 2013
I came across some code and it's not clear why it is casting an unsigned char * to another pointer type only to free it right after. Here are the relevant structures:
Code:
struct _Edje_Message {
Edje *edje;
Edje_Queue queue;
Edje_Message_Type type;
int id;
unsigned char *msg;
[Code] .....
As you can see, _Edge_Message has a *msg field, but in the function below, they cast it to the other two structure types inside the case blocks of the switch statement only to free it. What is the point or advantage of doing this?
Code:
void
_edje_message_free(Edje_Message *em) {
if (em->msg) {
int i;
switch (em->type) {
[Code] ......
View 14 Replies
View Related
Apr 20, 2013
I have an array of char pointers:
Code: char *input_args[MAX_ARGS];
And I have this function:
Code: BOOL parseArgs(char **input_args[], input arg_num);
I am trying to pass a pointer to this char pointer array like this:
Code: parseArgs(&input_args, args_num);
But the compiler is complaining:
Code: warning: passing argument 1 of 'parseArgs' from incompatible pointer type ...
note: expected 'char ***' but argument is of type 'char * (*)[20]'
Tried a bunch of stuff but nothing works.
View 4 Replies
View Related
Jan 28, 2013
Ok, I'm having a few problems with strings, mostly string functions saying they're not able to compare a string with a char pointer.
int main()
{
int counter = 0;
int x, y, z;
[Code].....
My goal is to take in a command and store it in a string. Different commands have different amounts of information I need. One command is "new flight <flightnumber> <seats available>". First, I try to understand which command is being asked, using the first character to decide. Once I can assume which command is being attempted, I try to separate the string into smaller strings (words) using strtok. I then compare the words that should be constant (new and flight), to make sure the command is syntactically correct (which I use strcmp for). Then I'll go on to create a new flight, which is a class that takes in a char * and integer (which is why I need to convert a char * to integer).
View 2 Replies
View Related
Feb 4, 2014
Why does this code doesnt work?
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
class my_string {
char* ptr;
[code] ....
View 1 Replies
View Related
Sep 8, 2014
Does uses of pointer in char type cause extra overhead?
View 7 Replies
View Related
Nov 28, 2014
I am trying to store data in a struct to be able to read it latter . have problems initializing this.
struct FoodAndDrink {
struct Food {
char* CannedGoods[2] = {
"Canned Spaghetti",
"Canned Tuna",
[code] .....
View 7 Replies
View Related
Jul 13, 2013
I have function that looks like this myfoo(char* Name) Now i want to compare this name to another one . But the another name is a pointer . This my code :
bool Tribe::RemoveSurvavior(char *H_Name) {
const char *p;
p=SurpointArr[i]->GetSurvivor_Name();
}
I need to compare if p is same as H_Name.
Mine is do it with for on each element but when i use sizeof it gives me size of char and not real size of the name.
View 6 Replies
View Related