69,373
社区成员
发帖
与我相关
我的任务
分享
//用stl的string,问题很简单的
#include <string>
#include <iostream>
using namespace std;
void main()
{
std::string str1 = "12789.56";
std::string res = str1.substr(0,str1.find(".",0,1)-1)+str1.substr(str1.find(".",0,1)+1,str1.size());
cout<<res<<endl;//res就是你想要的东西咯
}
void chardel(char *source, const char sub)
{
char *pc1, *pc2;
int isource;
isource= strlen(source);
while(*source != 0)
{
pc1 = source;
if(sub == *pc1)
{
memmove(pc1, pc1+1, strlen(source));
} else {
source++;
}
}
}
int main()
{
char str[32] = "1328.00";
chardel(str, '.');
}
chardel
/* d.c
* 如何去掉字符串中的小数点?
* 比如: 字符串 12789.56 转换为 1278956
* 字符串 1328.00 转换为 132800
* 字符串 1356.10 转换为 135610
*/
#include <stdio.h>
#include <stdlib.h>
void judge_argc(int argc);
void judge_inputdata(char *pInputData);
void del_dot(char *pInputData);
void display(char *argv);
int main(int argc,char *argv[])
{
judge_argc(argc);
judge_inputdata(argv[1]);
del_dot(argv[1]);
display(argv[1]);
return 0;
}
/**
* @brief
* This function named judge_argc is used for judging the number of
*data inputed from command line.
*If the data is wrong,it will show an information prompts error.
*@param argc the number of the command line param.
*/
void judge_argc(int argc)
{
if(argc < 2)
{
printf("Input Error!\nUsage:programmename data\n");
exit(0);
}
}
/**
* @brief
* This function named judge_inputdata is used for judging the validity of
*data inputed from command line.
*If the data is wrong,it will show an information prompts error.
*@param pInputData the pointer of the command line param array.
*/
void judge_inputdata(char *pInputData)
{
int i;
/* ASCII code:+:043 -:045 .:046 0-9:048-057 */
for(i = 0;i < strlen(pInputData);i++)
{
if(((pInputData[i] >= 48) && (pInputData[i] <= 57)) || (pInputData[i] == 46))
{
continue;
}
else
{
if(((pInputData[i] == 43) || (pInputData[i] == 45)) && (i == 0))
{
continue;
}
else
{
printf("Input Error!\n(The inputed data must be the numbers 0-9 or + - . and + - must be the first.)\n");
exit(0);
}
}
}
}
/**
* @brief
* This function named del_dot is used for delete the dot in the data.
*@param pInputData the pointer of the command line param array.
*/
void del_dot(char *pInputData)
{
int i,j,k;
int iFlag = 0; /* the number of the dot */
int iLen = strlen(pInputData);
for(i = 0;i < iLen;i++)
{
if(pInputData[i] == '.')
{
iFlag = iFlag + 1;
for(j = (i + 1),k = i;j < iLen;j++,k++)
{
pInputData[k] = pInputData[j];
}
}
}
if(0 != iFlag)
{
for(i = 0;i < iFlag;i++)
{
pInputData[iLen - i - 1] = '\0';
}
}
}
/**
* @brief
* This function named display is used for display the processed data.
*@param argv the pointer of the processed data.
*/
void display(char *argv)
{
int i;
printf("The processed data is:\n");
for(i = 0;i < strlen(argv);i++)
{
printf("%c",argv[i]);
}
printf("\n");
}
#include <string.h>
#include <iostream>
using namespace std;
int main()
{
char* str = "1328.00";
int temp = atoi(str);
cout<<temp*100<<endl;
}
void qd(char *p)
{
int i=0;
while(p[i]!='.' && p[i]!='\0')i++;
if(p[i]!='\0')strcpy(p+i,p+i+1);//如果字符串中没有小数点就不用去除
}
#include <string.h>
#include <stdio.h>
#include <malloc.h>
char* getoutpoint(char* s)
{
int i, j,len = strlen(s);
char* out =malloc(len);
for(i=0,j=0; i<len;i++)
{
if(*(s+i)!='.')
{
out[j]= *(s+i);
/* printf("%c\t%d\n",out[j],j); */
j++;
}
}
out[j] = '\0';
return out;
}
int main()
{
char* p1 = getoutpoint("12789.56");
printf("%s\n",p1);
getch();
free(p1);
return 0;
}
#include <string.h>
#include <stdio.h>
int main(void)
{
char input[16] = "abc,d";
char *p;
/* strtok places a NULL terminator
in front of the token, if found */
p = strtok(input, ",");
if (p) printf("%s
", p);
/* A second call to strtok using a NULL
as the first parameter returns a pointer
to the character following the token */
p = strtok(NULL, ",");
if (p) printf("%s
", p);
return 0;
}
#include <stdio.h>
char* Modify(char* str)
{
char* curr = str, * ret = str;
while (*curr=*str++)
if (*curr != '.') curr++;
return ret;
}
int main(int argc, char* argv[])
{
char data[][32] = {"12789.56", "1328.00", "1356.10"};
int i;
for (i = 0; i < sizeof(data)/sizeof(data[0]); ++i)
printf("%s\n", Modify(data[i]));
return 0;
}