I'm trying to write a method which will return the extension of a file given the file's name, e.g. test.txt should return txt. I'm using C so am limited to char pointers and arrays. Here is the code as I have it:
I know this could return a null pointer but I'm just trying to get it working before I clean it up. I'm getting this compile warning:
Line 106 is the strcat() call. Does somebody have a simple way of adding a single character to a char pointer? I'm not a great C programmer and have never really fully understood the concept of pointers.
Hi,
char *s="yamaha";
cout<<s<<endl;
int *p;
int i=10;
p=&i;
cout<<p<<endl;
1) For the 1st "cout" we will get "yamaha" as output. That is we are getting "content of the address" for cout<<s.
2) But for integer "cout<<p" we are getting the "address only".
Please clarify how we are... (2 Replies)
Hi,
How to replace any character in a file with a newline character using sed ..
Ex:
To replace ',' with newline
Input:
abcd,efgh,ijkl,mnop
Output:
abcd
efgh
ijkl
mnop
Thnx in advance.
Regards,
Sasidhar (5 Replies)
I am writing a bash shell menu and would like to get a char immediately after a key is pressed. This script does not work but should give you an idea of what I am trying to do....
Thanks for the help
#! /bin/bash
ANSWER=""
echo -en "Choose item...\n"
until
do
$ANSWER = $STDIN
... (2 Replies)
I'm trying to run a script which will ssh to several other servers (All Solaris 10) and execute a sar -f command to get each server's CPU usage for a given hour.
It kinda works OK but I just can't figure out how to separate the returned fields with a Tab character. I've done lots of searching... (2 Replies)
The below code throws the error, since the size of x = 19 is not passed to the cstrCopy function.
using namespace std;
static void cstrCopy(char *x, const char*y);
int main ()
{
char x;
const string y = "UNIX FORUM";
cstrCopy(x,y.c_str());
return 0;
}
void cstrCopy(char *x,... (3 Replies)
Compiling xpp (The X Printing Panel) on SL6 (RHEL6 essentially):
xpp.cxx: In constructor ‘printFiles::printFiles(int, char**, int&)’:
xpp.cxx:200: error: invalid conversion from ‘const char*’ to ‘char*’
The same error with all c++ constructors - gcc 4.4.4.
If anyone can throw any light on... (8 Replies)
Task 2:
When Im tring script called char that checks a single character on the
command line, c. If the character is a digit, digit is displayed. If the
character is an upper or lowercase alphabetic character, letter is
displayed. Otherwise, other is displayed. Have the script print an
error... (0 Replies)
Pointers are seeming to get the best of me and I get that error in my program.
Here is the code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define REPORTHEADING1 " Employee Pay Hours Gross Tax Net\n"
#define REPORTHEADING2 " Name ... (1 Reply)
I am passing a char* to the function "reverse" and when I execute it with gdb I get:
Program received signal SIGSEGV, Segmentation fault.
0x000000000040083b in reverse (s=0x400b2b "hello") at pointersExample.c:72
72 *q = *p;
Attached is the source code.
I do not understand why... (9 Replies)
Discussion started by: jose_spain
9 Replies
LEARN ABOUT MOJAVE
string
STRING(3) BSD Library Functions Manual STRING(3)NAME
index, rindex, stpcpy, strcasecmp, strcat, strchr, strcmp, strcpy, strcspn, strerror, strlen, strncasecmp, strncat, strncmp, strncpy,
strpbrk, strrchr, strsep, strspn, strstr, strtok -- string specific functions
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <strings.h>
char *
index(const char *s, int c);
char *
rindex(const char *s, int c);
int
strcasecmp(const char *s1, const char *s2);
int
strncasecmp(const char *s1, const char *s2, size_t n);
#include <string.h>
char *
stpcpy(char *dst, const char *src);
char *
strcat(char *restrict s1, const char *restrict s2);
char *
strchr(const char *s, int c);
int
strcmp(const char *s1, const char *s2);
char *
strcpy(char *restrict s1, const char *restrict s2);
size_t
strcspn(const char *s1, const char *s2);
char *
strerror(int errnum);
size_t
strlen(const char *s);
char *
strncat(char *restrict s1, const char *restrict s2, size_t n);
int
strncmp(const char *s1, const char *s2, size_t n);
char *
strncpy(char *restrict s1, const char *restrict s2, size_t n);
char *
strpbrk(const char *s1, const char *s2);
char *
strrchr(const char *s, int c);
char *
strsep(char **stringp, const char *delim);
size_t
strspn(const char *s1, const char *s2);
char *
strstr(const char *s1, const char *s2);
char *
strtok(char *restrict s1, const char *restrict s2);
DESCRIPTION
The string functions manipulate strings that are terminated by a null byte.
See the specific manual pages for more information. For manipulating variable length generic objects as byte strings (without the null byte
check), see bstring(3).
Except as noted in their specific manual pages, the string functions do not test the destination for size limitations.
SEE ALSO bstring(3), index(3), rindex(3), stpcpy(3), strcasecmp(3), strcat(3), strchr(3), strcmp(3), strcpy(3), strcspn(3), strerror(3), strlen(3),
strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3), strtok(3)STANDARDS
The strcat(), strncat(), strchr(), strrchr(), strcmp(), strncmp(), strcpy(), strncpy(), strerror(), strlen(), strpbrk(), strspn(), strcspn(),
strstr(), and strtok() functions conform to ISO/IEC 9899:1990 (``ISO C90'').
BSD December 11, 1993 BSD